package com.broada.apm.service.impl;

import java.io.OutputStream;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.time.StopWatch;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.util.CellRangeAddress;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.broada.apm.ajax.PerformanceResult;
import com.broada.apm.base.BaseService;
import com.broada.apm.entity.OrderClass;
import com.broada.apm.entity.Service;
import com.broada.apm.model.ApplicationSystem;
import com.broada.apm.model.PerformanceView;
import com.broada.apm.service.ReportService;
import com.broada.apm.util.Constants;

public class ReportServiceImpl extends BaseService implements ReportService {
	private final static Logger log = LoggerFactory.getLogger(ReportServiceImpl.class);
	String[] YJH_STABILITY_LEVEL1 = {"核心业务系统", "综合前置系统", "信用卡系统", "网上银行系统"};
	String[] YJH_STABILITY_LEVEL11 = {"电话银行系统", "手机银行"};
	String[] YJH_STABILITY_LEVEL2 = {"资金变动类", "非资金变动类", "大小额支付前置系统", "ATM前置系统", "银联前置系统", "超级网银前置系统", "POS渠道", "第三方存管前置系统", "电话银行渠道"
			, "手机银行渠道", "ATM渠道", "POS渠道", "个人网银", "企业网银"};
	String[] YJH_SCALE_LEVEL1 = {"网上银行", "电话银行", "手机银行", "ATM", "POS"};
	String[] RESULT_KEY = {"核心业务系统_资金变动类", "核心业务系统_非资金变动类", "综合前置系统_大小额支付前置系统", "综合前置系统_ATM前置系统", "综合前置系统_银联前置系统", "综合前置系统_超级网银前置系统", "综合前置系统_POS渠道", 
			"综合前置系统_第三方存管前置系统", "信用卡系统_电话银行渠道", "信用卡系统_手机银行渠道", "信用卡系统_ATM渠道", "信用卡系统_POS渠道", "网上银行系统_个人网银", "网上银行系统_企业网银", "电话银行系统", "手机银行"};

	@Override
	public PerformanceResult querySystemAvailability(long startDate, long endDate) {
		long startTime1 = System.currentTimeMillis();
		PerformanceResult result = new PerformanceResult();
		if ("NaN".equals(startDate) || "NaN".equals(endDate)) {
			result.setFailMessage("时间参数是NAN");
			return result;
		}
		if (endDate == 0)
			endDate = System.currentTimeMillis();
		if (startDate == 0)
			startDate = endDate - 60 * 60 * 1000;
		
		List<PerformanceView> appPerfList = new ArrayList<PerformanceView>();
		try {
			long history_startDate = startDate;
			long history_endDate = endDate;
			if ((endDate - startDate) <= 24 * 60 * 60 * 1000) {
				history_startDate = startDate - 24 * 60 * 60 * 1000;
				history_endDate = endDate - 24 * 60 * 60 * 1000;
			} else if ((endDate - startDate) <= 7 * 24 * 60 * 60 * 1000) {
				history_startDate = startDate - 7 * 24 * 60 * 60 * 1000;
				history_endDate = endDate - 7 * 24 * 60 * 60 * 1000;
			} else {
				Calendar sd = Calendar.getInstance();
				sd.setTime(new Date(startDate));
				sd.set(Calendar.HOUR_OF_DAY, 0);
				sd.set(Calendar.MINUTE, 0);
				sd.set(Calendar.SECOND, 0);
				sd.set(Calendar.MILLISECOND, 0);
				sd.add(Calendar.MONTH, -1);
				
				Calendar ed = Calendar.getInstance();
				ed.setTime(new Date(endDate));
				ed.set(Calendar.HOUR_OF_DAY, 0);
				ed.set(Calendar.MINUTE, 0);
				ed.set(Calendar.SECOND, 0);
				ed.set(Calendar.MILLISECOND, 0);
				ed.add(Calendar.MONTH, -1);
				
				history_startDate = sd.getTime().getTime();
				history_endDate = ed.getTime().getTime();
			}
			long startTime2 = System.currentTimeMillis();
			Map<String, com.broada.apm.entity.ApplicationSystem> appMap = new HashMap<String, com.broada.apm.entity.ApplicationSystem>();
			Map<String, PerformanceView> availablePerfMap = new HashMap<String, PerformanceView>();
			Map<String, PerformanceView> historyAppPerfMap = new HashMap<String, PerformanceView>();
			List<com.broada.apm.entity.ApplicationSystem> applicationList = appLogic.queryApplications();
			for (com.broada.apm.entity.ApplicationSystem app : applicationList) {
				appMap.put(app.getId(), app);
			}
			List<PerformanceView> appPerformanceList = perfLogic.queryAppPerfs(null, new Date(startDate), new Date(endDate));
			List<PerformanceView> availablePerfList = perfLogic.queryAppPerfs(appMap.keySet(), new Date(startDate), new Date(endDate));
			List<PerformanceView> historyAppPerfList = perfLogic.queryAppPerfs(appMap.keySet(), new Date(history_startDate), new Date(history_endDate));
			for (PerformanceView availablePerf : availablePerfList) {
				availablePerfMap.put(availablePerf.getApplicationId(), availablePerf);
			}
			for (PerformanceView historyAppPerf : historyAppPerfList) {
				historyAppPerfMap.put(historyAppPerf.getApplicationId(), historyAppPerf);
			}
			log.error("系统可用性报表ES查询用时：" + (System.currentTimeMillis() - startTime2));
			long startTime3 = System.currentTimeMillis();
			for (PerformanceView appPerf : appPerformanceList) {
				com.broada.apm.entity.ApplicationSystem application = appMap.get(appPerf.getApplicationId());
				if (application == null) continue;
				PerformanceView availablePerf = availablePerfMap.get(application.getId());
				appPerf.put("appName", application.getName());
				appPerf.put("appServerTime", (long)Double.parseDouble(appPerf.get("count").toString())); // 提供服务总时间
				if (availablePerf != null) {
					appPerf.put("appAvailableRate", new DecimalFormat("0.00")
							.format(Double.parseDouble(availablePerf.get("availableCount").toString())
									/ Double.parseDouble(appPerf.get("count").toString()) * 100 > 100 ? 100
											: Double.parseDouble(availablePerf.get("availableCount").toString())
													/ Double.parseDouble(appPerf.get("count").toString()) * 100)); // 系统可用率
					appPerf.put("appInterruptTime",
							(long) (Double.parseDouble(appPerf.get("count").toString())
									- Double.parseDouble(availablePerf.get("availableCount").toString()) < 0 ? 0.0
											: Double.parseDouble(appPerf.get("count").toString()) - Double
													.parseDouble(availablePerf.get("availableCount").toString()))); // 中断时间
					appPerf.put("appInterruptCount", (long) Double.parseDouble(appPerf.get("count").toString())
							- Double.parseDouble(availablePerf.get("availableCount").toString())); // 中断次数
				}
				if (appPerf.get("business/error/count") != null) {
					appPerf.put("business/throughput/total", (long)(Double.parseDouble(appPerf.get("business/throughput/total").toString())));
					appPerf.put("business/success/count", (long)(Double.parseDouble(appPerf.get("business/throughput/total").toString()) - Double.parseDouble(appPerf.get("business/error/count").toString())));
					appPerf.put("business/success/rate",
							Double.parseDouble(appPerf.get("business/throughput/total").toString()) != 0 ? 
									new DecimalFormat("0.00").format((Double.parseDouble(appPerf.get("business/throughput/total").toString())
											- Double.parseDouble(appPerf.get("business/error/count").toString()))
											/ Double.parseDouble(appPerf.get("business/throughput/total").toString())
											* 100) : "-");
				} else {
					appPerf.put("business/success/count", "-");
					appPerf.put("business/success/rate", "-");
				}
				// 查询上期交易数据
				PerformanceView historyAppPerf = historyAppPerfMap.get(application.getId());
				if (historyAppPerf != null) {
					appPerf.put("history_business/throughput/total", (long)Double.parseDouble(historyAppPerf.get("business/throughput/total").toString())); // 上期交易量
					appPerf.put("business/throughput/total_rate",
							(historyAppPerf.get("business/throughput/total") == null 
							|| Double.parseDouble(historyAppPerf.get("business/throughput/total").toString()) == 0)
											? "-" : new DecimalFormat("0.00").format(((Double.parseDouble(appPerf.get("business/throughput/total").toString())
													- Double.parseDouble(historyAppPerf.get("business/throughput/total").toString()))
													/ Double.parseDouble(historyAppPerf.get("business/throughput/total").toString()))
													* 100)); // 变化率
				} else {
					appPerf.put("history_business/throughput/total", "-");
					appPerf.put("business/throughput/total_rate", "-");
				}
				appPerfList.add(appPerf);
			}
			log.error("系统可用性报表循环数据处理用时：" + (System.currentTimeMillis() - startTime3));
		} catch (Exception e) {
			result.setFailMessage("查询系统可用性报表数据失败");
		}

		result.setPerformances(appPerfList);
		result.setPerformances(tradeSort(appPerfList, "appAvailableRate", "desc", appPerfList.size()));
		log.error("系统可用性报表总用时：" + (System.currentTimeMillis() - startTime1));
		return result;
	}

	@Override
	public PerformanceResult querySystemFault(long startDate, long endDate) {
		long startTime1 = System.currentTimeMillis();
		PerformanceResult result = new PerformanceResult();
		List<PerformanceView> perfList = new ArrayList<PerformanceView>();
		List<com.broada.apm.entity.ApplicationSystem> applications = appLogic.queryApplications();
		
		Map<String, Map<String, String>> alertCount = alertLogic.queryAlertCountBySeverity("application_id", new Date(startDate), new Date(endDate));
		Map<String, Map<String, String>> alertTypeCount = alertLogic.queryAlertCountByType("application_id", new Date(startDate), new Date(endDate));
		Map<String, Map<String, String>> serviceAlertCount = alertLogic.queryAlertCountBySeverity("service_id", new Date(startDate), new Date(endDate));
		Map<String, Map<String, String>> serviceAlertTypeCount = alertLogic.queryAlertCountByType("service_id", new Date(startDate), new Date(endDate));
		
		for (com.broada.apm.entity.ApplicationSystem app : applications) {
			PerformanceView perf = new PerformanceView();
			perf.setAlertPerfBasic();
			if (alertCount.get(app.getId()) != null) perf.putAll(alertCount.get(app.getId()));
			if (alertTypeCount.get(app.getId()) != null) perf.putAll(alertTypeCount.get(app.getId()));
			List<Service> serviceList = serverLogic.queryServiceByAppId(app.getId());
			List<PerformanceView> serviceAlertList = new ArrayList<PerformanceView>();
			for (Service service : serviceList) {
				PerformanceView servicePerf = new PerformanceView();
				servicePerf.setAlertPerfBasic();
				servicePerf.put("serviceName", service.getName());
				if (service.getNodeType() == 2) {
					continue;
				} else {
					if (serviceAlertCount.get(service.getId()) != null) servicePerf.putAll(serviceAlertCount.get(service.getId()));
					if (serviceAlertTypeCount.get(service.getId()) != null) servicePerf.putAll(serviceAlertTypeCount.get(service.getId()));
				}
				serviceAlertList.add(servicePerf);
			}
			if (serviceAlertList.size() > 1) {
				serviceAlertList = ServiceSort(serviceAlertList, "50Count", "desc");
			}
			perf.put("service", serviceAlertList);
			perf.put("appName", app.getName());
			perfList.add(perf);
		}
//		result.setPerformances(perfList);
		result.setPerformances(tradeSort(perfList, "50Count", "desc", perfList.size()));
		log.error("系统故障报表总用时：" + (System.currentTimeMillis() - startTime1));
		return result;
	}
	
	private List<PerformanceView> ServiceSort(List<PerformanceView> staticPerf, String orderBy, String orderDirection) {
		long startTime2 = System.currentTimeMillis();
		List<OrderClass> list = new ArrayList<OrderClass>();
		List<PerformanceView> staticPerf2 = new ArrayList<PerformanceView>();
		for (int i=0;i<staticPerf.size();i++) {
			OrderClass order= new OrderClass();
			PerformanceView performanceView = staticPerf.get(i);
			
			order.setPerformanceView(performanceView);
			order.setOrder("-".equals(performanceView.get(orderBy)) ? 0.0 : Double.parseDouble(performanceView.get(orderBy).toString()));
			list.add(order);
		}
		
		if (orderDirection.equals("asc")) {
			Collections.sort(list, new Comparator<OrderClass>() {
				public int compare(OrderClass arg0, OrderClass arg1) {
					return arg0.getOrder().compareTo(arg1.getOrder());
				}
			});
		} else {
			Collections.sort(list, new Comparator<OrderClass>() {
				public int compare(OrderClass arg0, OrderClass arg1) {
					return arg1.getOrder().compareTo(arg0.getOrder());
				}
			});
		}
		
		if (list.size() > 3) {
			for (int i=0;i<3;i++) {
				OrderClass orderClass= list.get(i);
				staticPerf2.add(i, orderClass.getPerformanceView());
			}
		} else {
			for (int i=0;i<list.size();i++) {
				OrderClass orderClass= list.get(i);
				staticPerf2.add(i, orderClass.getPerformanceView());
			}
		}
		log.error("系统故障报表排序用时：" + (System.currentTimeMillis() - startTime2));
		return staticPerf2;
		
	}

	@Override
	public PerformanceResult queryTradeTypePerf(String appId, long startDate, long endDate) {
		long startTime1 = System.currentTimeMillis();
		PerformanceResult result = new PerformanceResult();
		if (StringUtils.isBlank(appId)) {
			result.setFailMessage("参数错误");
			return result;
		}
		
		if ("NaN".equals(endDate) || "NaN".equals(startDate)) {
			result.setFailMessage("查询时间错误");
			return result;
		}
		
		List<PerformanceView> performanceViews = new ArrayList<PerformanceView>();
		try {
			long history_startDate = startDate;
			long history_endDate = endDate;
			if ((endDate - startDate) <= 24 * 60 * 60 * 1000) {
				history_startDate = startDate - 24 * 60 * 60 * 1000;
				history_endDate = endDate - 24 * 60 * 60 * 1000;
			} else if ((endDate - startDate) <= 7 * 24 * 60 * 60 * 1000) {
				history_startDate = startDate - 7 * 24 * 60 * 60 * 1000;
				history_endDate = endDate - 7 * 24 * 60 * 60 * 1000;
			} else {
				Calendar sd = Calendar.getInstance();
				sd.setTime(new Date(startDate));
				sd.set(Calendar.HOUR_OF_DAY, 0);
				sd.set(Calendar.MINUTE, 0);
				sd.set(Calendar.SECOND, 0);
				sd.set(Calendar.MILLISECOND, 0);
				sd.add(Calendar.MONTH, -1);
				
				Calendar ed = Calendar.getInstance();
				ed.setTime(new Date(endDate));
				ed.set(Calendar.HOUR_OF_DAY, 0);
				ed.set(Calendar.MINUTE, 0);
				ed.set(Calendar.SECOND, 0);
				ed.set(Calendar.MILLISECOND, 0);
				ed.add(Calendar.MONTH, -1);
				
				history_startDate = sd.getTime().getTime();
				history_endDate = ed.getTime().getTime();
			}

			if (StringUtils.isNotBlank(appId)) {
				performanceViews = processData(startDate, endDate, history_startDate, history_endDate, appId, performanceViews);
			}
		} catch (Exception e) {
			result.setFailMessage("查询关键交易性能失败");
		}
		result.setPerformances(tradeSort(performanceViews, "count", "desc", performanceViews.size()));
		log.error("交易性能报表总用时：" + (System.currentTimeMillis() - startTime1));
		return result;
	}
	
	@SuppressWarnings("unchecked")
	private List<PerformanceView> processData(long startDate, long endDate, long history_startDate, long history_endDate, String appId, List<PerformanceView> performanceViews) {
		List<PerformanceView> typePerfs = new ArrayList<PerformanceView>();
		List<Service> serviceList = serverLogic.queryServiceByAppId(appId);
		Map<String, String> serviceMap = new HashMap<String, String>();
		Map<String, PerformanceView> hisPerfMap = new HashMap<String, PerformanceView>();
		for (Service service : serviceList) {
			if (service.getNodeType() == 2) continue;
			serviceMap.put(service.getId(), service.getName());
		}
		long startTime = System.currentTimeMillis();
		typePerfs = tradePerformanceLogic.getChannelAndTypeByService(appId, serviceMap.keySet(), new Date(startDate - 60 * 1000), new Date(endDate - 60 * 1000));
		List<PerformanceView> hisTypePerfs = tradePerformanceLogic.getChannelAndTypeByService(appId, serviceMap.keySet(), new Date(history_startDate - 60 * 1000), new Date(history_endDate - 60 * 1000));
		log.info("交易性能报表ES查询耗时：" + (System.currentTimeMillis() - startTime));
		for (PerformanceView hisperf : hisTypePerfs) {
			hisPerfMap.put(hisperf.getServiceId() + hisperf.get("typeName"), hisperf);
		}
		startTime = System.currentTimeMillis();
		for (PerformanceView typePerf : typePerfs) {
			
			PerformanceView hisPerfView = hisPerfMap.get(typePerf.getServiceId() + typePerf.get("typeName"));
			if (hisPerfView != null) {
				// 交易量环比
				typePerf.put("business/throughput/sequential_rate",
						(hisPerfView.get("count") == null || Double.parseDouble(hisPerfView.get("count").toString()) == 0) ? "-" : new DecimalFormat("0.00").format((Double.parseDouble(typePerf.get("count").toString())
								- Double.parseDouble(hisPerfView.get("count").toString()))
								/ Double.parseDouble(hisPerfView.get("count").toString()) * 100));
				
				// 响应时间环比
				new BigDecimal(Double.parseDouble(typePerf.get("responseTime").toString())).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
				String time_rate = new DecimalFormat("0.00").format((new BigDecimal(Double.parseDouble(typePerf.get("responseTime").toString()) / 1000).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()
						- new BigDecimal(Double.parseDouble(hisPerfView.get("responseTime").toString()) / 1000).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue())
						/ new BigDecimal(Double.parseDouble(hisPerfView.get("responseTime").toString()) / 1000).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue() * 100);
				typePerf.put("business/response_time/sequential_rate",
						(hisPerfView.get("responseTime") == null || Double.parseDouble(hisPerfView.get("responseTime").toString()) == 0) ? "-" : "-0.00".equals(time_rate) ? "0.00" : time_rate);
				// 成功率环比
				if (hisPerfView.get("count") == null || Double.parseDouble(hisPerfView.get("count").toString()) == 0 || ((Double.parseDouble(hisPerfView.get("count").toString())
						- Double.parseDouble(hisPerfView.get("isError").toString()))
						/ Double.parseDouble(hisPerfView.get("count").toString()) * 100) == 0) {
					typePerf.put("business/success/sequential_rate", "-");
				} else {
					typePerf.put("business/success/sequential_rate",
							new DecimalFormat("0.00").format(((Double.parseDouble(typePerf.get("count").toString())
									- Double.parseDouble(typePerf.get("isError").toString()))
									/ Double.parseDouble(typePerf.get("count").toString())
									- (Double.parseDouble(hisPerfView.get("count").toString())
											- Double.parseDouble(hisPerfView.get("isError").toString()))
											/ Double.parseDouble(hisPerfView.get("count").toString()))
							/ ((Double.parseDouble(hisPerfView.get("count").toString())
									- Double.parseDouble(hisPerfView.get("isError").toString()))
									/ Double.parseDouble(hisPerfView.get("count").toString()) * 100)));
				}
				// 错误数环比
				typePerf.put("business/error_count/sequential_rate",
						(hisPerfView.get("isError") == null || Double.parseDouble(hisPerfView.get("isError").toString()) == 0) ? "-" : new DecimalFormat("0.00").format((Double.parseDouble(typePerf.get("isError").toString())
								- Double.parseDouble(hisPerfView.get("isError").toString()))
								/ Double.parseDouble(hisPerfView.get("isError").toString()) * 100));
				
			}
			typePerf.put("serviceName", serviceMap.get(typePerf.getServiceId()));
			typePerf.put("responseTime", typePerf.get("responseTime") == null ? "-" : new DecimalFormat("0.00").format(Double.parseDouble(typePerf.get("responseTime").toString()) / 1000));
			typePerf.put("success_rate", Double.parseDouble(typePerf.get("count").toString()) == 0 ? "-" : new DecimalFormat("0.00").format((Double.parseDouble(typePerf.get("count").toString()) - Double.parseDouble(typePerf.get("isError").toString())) / Double.parseDouble(typePerf.get("count").toString()) * 100));
			
			typePerf.put("count", (typePerf.get("count") == null || Double.parseDouble(typePerf.get("count").toString()) == 0) ? "0" :(long)Double.parseDouble(typePerf.get("count").toString()));
			typePerf.put("isError", (typePerf.get("isError") == null || Double.parseDouble(typePerf.get("isError").toString()) == 0) ? "0" :(long)Double.parseDouble(typePerf.get("isError").toString()));
			for (Map<String, Object> channel : (List<Map<String, Object>>) typePerf.get("channel")) {
				
				if (hisPerfView != null) {
					for (Map<String, Object> hisChannel : (List<Map<String, Object>>) hisPerfView.get("channel")) {
						if (String.valueOf(channel.get("channelName")).equals(String.valueOf(hisChannel.get("channelName")))) {
							channel.put("business/throughput/sequential_rate", (hisChannel.get("count") == null || Double.parseDouble(hisChannel.get("count").toString()) == 0) ? "-" : 
									new DecimalFormat("0.00").format((Double.parseDouble(channel.get("count").toString())
											- Double.parseDouble(hisChannel.get("count").toString()))
											/ Double.parseDouble(hisChannel.get("count").toString()) * 100));
							
							channel.put("business/response_time/sequential_rate", (hisChannel.get("responseTime") == null || Double.parseDouble(hisChannel.get("responseTime").toString()) == 0) ? "-" : 
									new DecimalFormat("0.00").format((new BigDecimal(Double.parseDouble(channel.get("responseTime").toString()) / 1000).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()
											- new BigDecimal(Double.parseDouble(hisChannel.get("responseTime").toString()) / 1000).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue())
											/ new BigDecimal(Double.parseDouble(hisChannel.get("responseTime").toString()) / 1000).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue() * 100));
							if (hisChannel.get("count") == null || Double.parseDouble(hisChannel.get("count").toString()) == 0 || ((Double.parseDouble(hisChannel.get("count").toString())
									- Double.parseDouble(hisChannel.get("isError").toString()))
									/ Double.parseDouble(hisChannel.get("count").toString()) * 100) == 0) {
								channel.put("business/success/sequential_rate", "-");
							} else {
								channel.put("business/success/sequential_rate",
										new DecimalFormat("0.00")
												.format(((Double.parseDouble(channel.get("count").toString())
														- Double.parseDouble(channel.get("isError").toString()))
														/ Double.parseDouble(channel.get("count").toString())
														- (Double.parseDouble(hisChannel.get("count").toString())
																- Double.parseDouble(hisChannel.get("isError").toString()))
																/ Double.parseDouble(hisChannel.get("count").toString()))
										/ ((Double.parseDouble(hisChannel.get("count").toString())
												- Double.parseDouble(hisChannel.get("isError").toString()))
												/ Double.parseDouble(hisChannel.get("count").toString()) * 100)));
							}
							channel.put("business/error_count/sequential_rate",
									(hisChannel.get("isError") == null || Double.parseDouble(hisChannel.get("isError").toString()) == 0) ? "-" : new DecimalFormat("0.00").format((Double.parseDouble(channel.get("isError").toString())
											- Double.parseDouble(hisChannel.get("isError").toString()))
											/ Double.parseDouble(hisChannel.get("isError").toString()) * 100));
							
						}
					}
				}
				channel.put("responseTime", channel.get("responseTime") == null ? "-" : new DecimalFormat("0.00").format(Double.parseDouble(channel.get("responseTime").toString()) / 1000));
				channel.put("success_rate", Double.parseDouble(channel.get("count").toString()) == 0 ? "-" : new DecimalFormat("0.00").format((Double.parseDouble(channel.get("count").toString()) - Double.parseDouble(channel.get("isError").toString())) / Double.parseDouble(channel.get("count").toString()) * 100));
				
				channel.put("count", (channel.get("count") == null || Double.parseDouble(channel.get("count").toString()) == 0) ? "0" : (long)Double.parseDouble(channel.get("count").toString()));
				channel.put("isError", (channel.get("isError") == null || Double.parseDouble(channel.get("isError").toString()) == 0) ? "0" : (long)Double.parseDouble(channel.get("isError").toString()));
			}
		}
		log.info("交易性能报表循环处理数据耗时：" + (System.currentTimeMillis() - startTime));
		return typePerfs;
	}

	@SuppressWarnings("unchecked")
	@Override
	public PerformanceResult queryTradeTypeSort(int top, long startDate, long endDate) {
		StopWatch watch = new StopWatch();
		long split = 0;
		long time;
		PerformanceResult result = new PerformanceResult();
		if ("NaN".equals(endDate) || "NaN".equals(startDate)) {
			result.setFailMessage("查询时间错误");
			return result;
		}

		List<PerformanceView> perfs = new ArrayList<PerformanceView>();
		try {
			List<com.broada.apm.entity.ApplicationSystem> apps = appLogic.queryApplications();
			Map<String, String> applications = new HashMap<String, String>();
			for (com.broada.apm.entity.ApplicationSystem app : apps) {
				applications.put(app.getId(), app.getName());
			}
			watch.start();
			perfs = tradePerformanceLogic.getTopTradeType("channelName", top, new Date(startDate - 60 * 1000), new Date(endDate - 60 * 1000), applications.keySet());
			watch.split();
			split = watch.getSplitTime();
			log.info("交易量总排行ES查询用时  【"+split+"】");
			for (PerformanceView perf : perfs) {
				perf.put("applicationName", applications.get(perf.get("serviceId").toString().substring(0, perf.get("serviceId").toString().lastIndexOf("-"))));
				perf.put("serviceName", serverLogic.queryServiceById(String.valueOf(perf.get("serviceId"))).getName());
				perf.put("responseTime", perf.get("responseTime") == null ? "-" : new DecimalFormat("0.00").format(Double.parseDouble(perf.get("responseTime").toString()) / 1000));
				perf.put("success_rate", Double.parseDouble(perf.get("count").toString()) == 0 ? "-" : new DecimalFormat("0.00").format((Double.parseDouble(perf.get("count").toString()) - Double.parseDouble(perf.get("isError").toString())) / Double.parseDouble(perf.get("count").toString()) * 100));
				perf.put("count", Double.parseDouble(perf.get("count").toString()) == 0 ? "0" : (long)Double.parseDouble(perf.get("count").toString()));
				perf.put("isError", Double.parseDouble(perf.get("isError").toString()) == 0 ? "0" : (long)Double.parseDouble(perf.get("isError").toString()));
				for (Map<String, Object> channel : (List<Map<String, Object>>) perf.get("channel")) {
					channel.put("responseTime", channel.get("responseTime") == null ? "-" : new DecimalFormat("0.00").format(Double.parseDouble(channel.get("responseTime").toString()) / 1000));
					channel.put("success_rate", Double.parseDouble(channel.get("count").toString()) == 0 ? "-" : new DecimalFormat("0.00").format((Double.parseDouble(channel.get("count").toString()) - Double.parseDouble(channel.get("isError").toString())) / Double.parseDouble(channel.get("count").toString()) * 100));
					channel.put("count", Double.parseDouble(channel.get("count").toString()) == 0 ? "0" : (long)Double.parseDouble(channel.get("count").toString()));
					channel.put("isError", Double.parseDouble(channel.get("isError").toString()) == 0 ? "0" : (long)Double.parseDouble(channel.get("isError").toString()));
				}
			}
		} catch (Exception e) {
			result.setFailMessage("查询交易量总排行失败");
		}
		result.setPerformances(tradeSort(perfs, "count", "desc", top));
		watch.split();
		time = watch.getSplitTime()-split;
		log.info("交易量总排行数据处理用时【"+time+"】");
		watch.stop();
		return result;
	}
	
	private List<PerformanceView> tradeSort(List<PerformanceView> staticPerf, String orderBy, String orderDirection, int top) {
		long startTime2 = System.currentTimeMillis();
		List<OrderClass> list = new ArrayList<OrderClass>();
		List<PerformanceView> staticPerf2 = new ArrayList<PerformanceView>();
		for (int i=0;i<staticPerf.size();i++) {
			OrderClass order= new OrderClass();
			PerformanceView performanceView = staticPerf.get(i);
			
			order.setPerformanceView(performanceView);
			order.setOrder("-".equals(performanceView.get(orderBy)) ? 0.0 : Double.parseDouble(performanceView.get(orderBy).toString()));
			list.add(order);
		}
		
		if (orderDirection.equals("asc")) {
			Collections.sort(list, new Comparator<OrderClass>() {
				public int compare(OrderClass arg0, OrderClass arg1) {
					return arg0.getOrder().compareTo(arg1.getOrder());
				}
			});
		} else {
			Collections.sort(list, new Comparator<OrderClass>() {
				public int compare(OrderClass arg0, OrderClass arg1) {
					return arg1.getOrder().compareTo(arg0.getOrder());
				}
			});
		}
		
		if (list.size() > top) {
			for (int i=0;i<top;i++) {
				OrderClass orderClass= list.get(i);
				staticPerf2.add(i, orderClass.getPerformanceView());
			}
		} else {
			for (int i=0;i<list.size();i++) {
				OrderClass orderClass= list.get(i);
				staticPerf2.add(i, orderClass.getPerformanceView());
			}
		}
		log.error("排序用时：" + (System.currentTimeMillis() - startTime2));
		return staticPerf2;
		
	}

	@SuppressWarnings("unchecked")
	@Override
	public PerformanceResult queryTradeSlowSort(int top, long startDate, long endDate) {
		StopWatch watch = new StopWatch();
		long split;
		long time;
		PerformanceResult result = new PerformanceResult();
		if ("NaN".equals(endDate) || "NaN".equals(startDate)) {
			result.setFailMessage("查询时间错误");
			return result;
		}
		List<com.broada.apm.entity.ApplicationSystem> apps = appLogic.queryApplications();
		Map<String, String> applications = new HashMap<String, String>();
		for (com.broada.apm.entity.ApplicationSystem app : apps) {
			applications.put(app.getId(), app.getName());
		}
		watch.start();
		watch.split();
		split = watch.getSplitTime();
		List<PerformanceView> perfList = tradePerformanceLogic.getTopTradeType("channelName", top, new Date(startDate - 60 * 1000), new Date(endDate - 60 * 1000), applications.keySet());
		watch.split();
		time = watch.getSplitTime()-split;
		split = time;
		log.info("最慢交易查询  ES查询用时【"+time+"】");
		String temp;
		DecimalFormat df = new DecimalFormat("0.00");
		double max;
		double min;
		double count;
		for (PerformanceView perf : perfList) {
			temp = perf.get("serviceId").toString();
			perf.put("applicationName", applications.get(temp.substring(0, temp.lastIndexOf("-"))));
			perf.put("serviceName", serverLogic.queryServiceById(String.valueOf(perf.get("serviceId"))).getName());
			perf.put("responseTime", perf.get("responseTime") == null ? "-" : df.format(Double.parseDouble(perf.get("responseTime").toString()) / 1000));
			max = perf.get("responseTime_max") == null ? 0 : Double.parseDouble(perf.get("responseTime_max").toString());
			perf.put("responseTime_max", df.format(max / 1000));
			min = perf.get("responseTime_min") == null ? 0 :Double.parseDouble(perf.get("responseTime_min").toString());
			perf.put("responseTime_min", df.format(min / 1000));
			perf.put("count", perf.get("count") == null ? "-" : (long)Double.parseDouble(perf.get("count").toString()));
			for (Map<String, Object> channel : (List<Map<String, Object>>) perf.get("channel")) {
				channel.put("responseTime", channel.get("responseTime") == null ? "-" : df.format(Double.parseDouble(channel.get("responseTime").toString()) / 1000));
				max = channel.get("responseTime_max") == null ? 0 : Double.parseDouble(channel.get("responseTime_max").toString());
				channel.put("responseTime_max", df.format(max / 1000));
				min = channel.get("responseTime_min") == null ? 0 : Double.parseDouble(channel.get("responseTime_min").toString());
				channel.put("responseTime_min", df.format(min / 1000));
				count = Double.parseDouble(channel.get("count").toString());
				channel.put("success_rate", count == 0 ? "-" : df.format((count - Double.parseDouble(channel.get("isError").toString()))/count * 100));
				channel.put("count", channel.get("count") == null ? "-" :(long)count);
			}
		}
		watch.split();
		time = watch.getSplitTime()-split;
		log.info("最慢交易查询  数据处理用时【"+time+"】");
		watch.stop();
		result.setPerformances(sortByCondition(perfList, "responseTime", "desc", top));
		return result;
	}

	@SuppressWarnings("unchecked")
	@Override
	public PerformanceResult queryTradeFailSort(int top, long startDate, long endDate) {
		StopWatch watch  = new StopWatch();
		long split;
		long time;
		PerformanceResult result = new PerformanceResult();
		if ("NaN".equals(endDate) || "NaN".equals(startDate)) {
			result.setFailMessage("查询时间错误");
			return result;
		}
		List<PerformanceView> performanceList = new ArrayList<PerformanceView>();
		List<com.broada.apm.entity.ApplicationSystem> apps = appLogic.queryApplications();
		Map<String, String> applications = new HashMap<String, String>();
		for (com.broada.apm.entity.ApplicationSystem app : apps) {
			applications.put(app.getId(), app.getName());
		}
		watch.start();
		List<PerformanceView> perfList = tradePerformanceLogic.getTopTradeType("responseCodeString", top, new Date(startDate - 60 * 1000), new Date(endDate - 60 * 1000), applications.keySet());
		watch.split();
		split = watch.getSplitTime();
		log.info("异常交易排行  ES数据查询用时【"+split+"】");
		double count;
		for (PerformanceView perf : perfList) {
			if (perf.get("isError") == null || Double.parseDouble(perf.get("isError").toString()) == 0) continue;
			perf.put("applicationName", applications.get(perf.get("serviceId").toString().substring(0, perf.get("serviceId").toString().lastIndexOf("-"))));
			perf.put("serviceName", serverLogic.queryServiceById(String.valueOf(perf.get("serviceId"))).getName());
			count = Double.parseDouble(perf.get("count").toString());
			perf.put("success_rate", count == 0 ? "-" : new DecimalFormat("0.00").format((Double.parseDouble(perf.get("count").toString()) - Double.parseDouble(perf.get("isError").toString())) / Double.parseDouble(perf.get("count").toString()) * 100));
			
			perf.put("count", count == 0 ? "-" : (long)count);
			List<Map<String, Object>> response = new ArrayList<Map<String, Object>>();
			for (Map<String, Object> channel : (List<Map<String, Object>>) perf.get("channel")) {
				if (channel.get("isError") == null || Double.parseDouble(channel.get("isError").toString()) == 0) continue;
				channel.put("isError", (long)Double.parseDouble(channel.get("isError").toString()));
				response.add(channel);
				if (response.size() == 3) break;
			}
			
			perf.put("response", response);
			perf.remove("channel");
			performanceList.add(perf);
		}
		result.setPerformances(sortByCondition(performanceList, "success_rate", "asc", top));
		watch.split();
		time = watch.getSplitTime()-split;
		log.info("异常交易排行  数据处理用时【"+time+"】");
		watch.stop();
		return result;
	}
	
	private List<PerformanceView> sortByCondition(List<PerformanceView> staticPerf, String orderBy,
			String orderDirection, int top) {
		List<OrderClass> list = new ArrayList<OrderClass>();
		List<PerformanceView> staticPerf2 = new ArrayList<PerformanceView>();
		for (int i = 0; i < staticPerf.size(); i++) {
			OrderClass order = new OrderClass();
			PerformanceView performanceView = staticPerf.get(i);
			order.setPerformanceView(performanceView);
			if ("-".equals(performanceView.get(orderBy))) {
				// performanceView.put(orderBy, 0.0);
				order.setOrder(0.0);
			} else {
				order.setOrder(Double.parseDouble(performanceView.get(orderBy).toString()));
			}
			list.add(order);
		}

		if (orderDirection.equals("asc")) {
			Collections.sort(list, new Comparator<OrderClass>() {
				public int compare(OrderClass arg0, OrderClass arg1) {
					return arg0.getOrder().compareTo(arg1.getOrder());
				}
			});
		} else {
			Collections.sort(list, new Comparator<OrderClass>() {
				public int compare(OrderClass arg0, OrderClass arg1) {
					return arg1.getOrder().compareTo(arg0.getOrder());
				}
			});
		}

		if (list.size() > top) {
			for (int i=0;i<top;i++) {
				OrderClass orderClass= list.get(i);
				staticPerf2.add(i, orderClass.getPerformanceView());
			}
		} else {
			for (int i=0;i<list.size();i++) {
				OrderClass orderClass= list.get(i);
				staticPerf2.add(i, orderClass.getPerformanceView());
			}
		}
		return staticPerf2;
	}

	@Override
	public PerformanceResult queryHttpSlowSort(String appId, int top, long startDate, long endDate) {
		long startTime1 = System.currentTimeMillis();
		PerformanceResult result = new PerformanceResult();
		if ("NaN".equals(endDate) || "NaN".equals(startDate)) {
			result.setFailMessage("查询时间错误");
			return result;
		}
		if (StringUtils.isBlank(appId)) {
			result.setFailMessage("未提供系统名称");
			return result;
		}
		if(top == 0){  //默认返回top10
			top = 10;
		}
		com.broada.apm.entity.ApplicationSystem app = appLogic.queryApplicationsByIds(new String[] {appId}).get(0);
		if(app != null){
			result.put("title", app.getName() + "系统最慢HTTP页面排行TOP" + top);
			List<PerformanceView> perfs = new ArrayList<PerformanceView>();
			long startTime2 = System.currentTimeMillis();
			perfs = tradePerformanceLogic.getHttpSlowSort(appId, top, new Date(startDate), new Date(endDate));
			log.error("最慢HTTP报表ES查询用时：" + (System.currentTimeMillis() - startTime2));
			result.setPerformancesResult(perfs);
		}
		log.error("最慢HTTP报表查询总用时：" + (System.currentTimeMillis() - startTime1));
		return result;
	}

	@Override
	public PerformanceResult queryHttpErrorSort(String appId, int top, long startDate, long endDate) {
		long startTime1 = System.currentTimeMillis();
		PerformanceResult result = new PerformanceResult();
		if ("NaN".equals(endDate) || "NaN".equals(startDate)) {
			result.setFailMessage("查询时间错误");
			return result;
		}
		if (StringUtils.isBlank(appId)) {
			result.setFailMessage("未提供系统名称");
			return result;
		}
		if(top == 0){  //默认返回top10
			top = 10;
		}
		com.broada.apm.entity.ApplicationSystem app = appLogic.queryApplicationsByIds(new String[] {appId}).get(0);
		if(app != null){
			result.put("title", app.getName() + "系统错误HTTP页面排行TOP" + top);
			List<PerformanceView> perfs = new ArrayList<PerformanceView>();
			long startTime2 = System.currentTimeMillis();
			perfs = tradePerformanceLogic.getHttpErrorSort(appId, top, new Date(startDate), new Date(endDate));
			log.error("错误HTTP报表ES查询用时：" + (System.currentTimeMillis() - startTime2));
			result.setPerformancesResult(perfs);
		}
		log.error("错误HTTP报表查询总用时：" + (System.currentTimeMillis() - startTime1));
		return result;
	}

	@Override
	public PerformanceResult querySqlSlowSort(String appId, int top, long startDate, long endDate) {
		long startTime1 = System.currentTimeMillis();
		PerformanceResult result = new PerformanceResult();
		if ("NaN".equals(endDate) || "NaN".equals(startDate)) {
			result.setFailMessage("查询时间错误");
			return result;
		}
		if (StringUtils.isBlank(appId)) {
			result.setFailMessage("未提供系统名称");
			return result;
		}
		if(top == 0){  //默认返回top10
			top = 10;
		}
		com.broada.apm.entity.ApplicationSystem app = appLogic.queryApplicationsByIds(new String[] {appId}).get(0);
		if(app != null){
			result.put("title", app.getName() + "系统最慢SQL排行TOP" + top);
			List<PerformanceView> perfs = new ArrayList<PerformanceView>();
			long startTime2 = System.currentTimeMillis();
			perfs = tradePerformanceLogic.getSqlSlowSort(appId, top, new Date(startDate), new Date(endDate));
			log.error("最慢SQL报表ES查询用时：" + (System.currentTimeMillis() - startTime2));
			result.setPerformancesResult(perfs);
		}
		log.error("最慢SQL报表查询总用时：" + (System.currentTimeMillis() - startTime1));
		return result;
	}

	@Override
	public PerformanceResult querySqlErrorSort(String appId, int top, long startDate, long endDate) {
		long startTime1 = System.currentTimeMillis();
		PerformanceResult result = new PerformanceResult();
		if ("NaN".equals(endDate) || "NaN".equals(startDate)) {
			result.setFailMessage("查询时间错误");
			return result;
		}
		if (StringUtils.isBlank(appId)) {
			result.setFailMessage("未提供系统名称");
			return result;
		}
		if(top == 0){  //默认返回top10
			top = 10;
		}
		com.broada.apm.entity.ApplicationSystem app = appLogic.queryApplicationsByIds(new String[] {appId}).get(0);
		if(app != null){
			result.put("title", app.getName() + "系统错误SQL排行TOP" + top);
			List<PerformanceView> perfs = new ArrayList<PerformanceView>();
			long startTime2 = System.currentTimeMillis();
			perfs = tradePerformanceLogic.getSqlErrorSort(appId, top, new Date(startDate), new Date(endDate));
			log.error("错误SQL报表ES查询用时：" + (System.currentTimeMillis() - startTime2));
			result.setPerformancesResult(perfs);
		}
		log.error("错误SQL报表查询总用时：" + (System.currentTimeMillis() - startTime1));
		return result;
	}

	@Override
	public void downloadHttpSlowSort(HttpServletRequest request, HttpServletResponse response, String appId, int top,
			long startDate, long endDate) {
		try {
			PerformanceResult result = new PerformanceResult();
			if ("NaN".equals(endDate) || "NaN".equals(startDate)) {
				result.setFailMessage("查询时间错误");
				return ;
			}
			if (StringUtils.isBlank(appId)) {
				result.setFailMessage("未提供系统名称");
				return ;
			}
			if(top == 0){  //默认返回top10
				top = 10;
			}
			List<PerformanceView> perfs = tradePerformanceLogic.getHttpSlowSort(appId, top, new Date(startDate), new Date(endDate));
			com.broada.apm.entity.ApplicationSystem app = appLogic.queryApplicationsByIds(new String[] {appId}).get(0);
			String appName = "";
			if(app != null){
				appName = app.getName();
			}
			String filename = URLEncoder.encode(appName + "系统最慢HTTP页面排行TOP" + top +".xls", "UTF-8");
			OutputStream outPut = response.getOutputStream();
			response.setContentType("application/vnd.ms-excel;charset=UTF-8");
			if("FF".equals(getBrowser(request))){
				response.setContentType("application/vnd.ms-excel;charset=ISO-8859-1");
				filename = new String(filename.getBytes("UTF-8"),"ISO-8859-1");
			}
			response.setHeader("Content-Disposition", "attachment; filename=" + filename + ";filename*=UTF-8''" + filename);

			HSSFWorkbook wb = new HSSFWorkbook();  
			HSSFSheet sheet = wb.createSheet("最慢HTTP页面排行");

			sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 9));
			Cell cell = sheet.createRow((int) 0).createCell(0);
			cell.setCellValue(appName + "系统最慢HTTP页面排行TOP" + top);
			cell.setCellStyle(createCellStyle(wb, 1));

			sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, 9));
			Cell cellt = sheet.createRow((int) 1).createCell(0);
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd");
			cellt.setCellValue(sdf.format(new Date(startDate)) + "-" + sdf.format(new Date(endDate)));
			cellt.setCellStyle(createCellStyle(wb, 2));

			createHttpSlowHead(sheet, 2, createCellStyle(wb, 3));
			createHttpSlowContent(sheet, 4, createCellStyle(wb, 4), perfs);

			wb.write(outPut);
			outPut.close();
		} catch(Exception e){
			log.error("查询性能数据失败：" + e.getMessage());
		}	
	}

	@Override
	public void downloadHttpErrorSort(HttpServletRequest request, HttpServletResponse response, String appId, int top,
			long startDate, long endDate) {
		try {
			PerformanceResult result = new PerformanceResult();
			if ("NaN".equals(endDate) || "NaN".equals(startDate)) {
				result.setFailMessage("查询时间错误");
				return ;
			}
			if (StringUtils.isBlank(appId)) {
				result.setFailMessage("未提供系统名称");
				return ;
			}
			if(top == 0){  //默认返回top10
				top = 10;
			}
			List<PerformanceView> perfs = tradePerformanceLogic.getHttpErrorSort(appId, top, new Date(startDate), new Date(endDate));
			OutputStream outPut = response.getOutputStream();
			response.setContentType("application/vnd.ms-excel;charset=UTF-8");
			
			com.broada.apm.entity.ApplicationSystem app = appLogic.queryApplicationsByIds(new String[] {appId}).get(0);
			String appName = "";
			if(app != null){
				appName = app.getName();
			}
			String filename = URLEncoder.encode(appName + "错误HTTP页面排行TOP" + top +".xls", "UTF-8");
			if("FF".equals(getBrowser(request))){
				response.setContentType("application/vnd.ms-excel;charset=ISO-8859-1");
				filename = new String(filename.getBytes("UTF-8"),"ISO-8859-1");
			}
			response.setHeader("Content-Disposition", "attachment; filename=" + filename + ";filename*=UTF-8''" + filename);

			HSSFWorkbook wb = new HSSFWorkbook();  
			HSSFSheet sheet = wb.createSheet("错误HTTP页面排行");
			
			sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 6));
			Cell cell = sheet.createRow((int) 0).createCell(0);
			cell.setCellValue(appName + "系统错误HTTP页面排行TOP" + top);
			cell.setCellStyle(createCellStyle(wb, 1));

			sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, 6));
			Cell cellt = sheet.createRow((int) 1).createCell(0);
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd");
			cellt.setCellValue(sdf.format(new Date(startDate)) + "-" + sdf.format(new Date(endDate)));
			cellt.setCellStyle(createCellStyle(wb, 2));

			createHttpErrorHead(sheet, 2, createCellStyle(wb, 3));
			createHttpErrorContent(sheet, 4, createCellStyle(wb, 4), perfs);

			wb.write(outPut);
			outPut.close();
		} catch(Exception e){
			log.error("查询性能数据失败：" + e.getMessage());
		}	
	}

	@Override
	public void downloadSqlSlowSort(HttpServletRequest request, HttpServletResponse response, String appId, int top,
			long startDate, long endDate) {
		try {
			PerformanceResult result = new PerformanceResult();
			if ("NaN".equals(endDate) || "NaN".equals(startDate)) {
				result.setFailMessage("查询时间错误");
				return ;
			}
			if (StringUtils.isBlank(appId)) {
				result.setFailMessage("未提供系统名称");
				return ;
			}
			if(top == 0){  //默认返回top10
				top = 10;
			}
			List<PerformanceView> perfs = tradePerformanceLogic.getSqlSlowSort(appId, top, new Date(startDate), new Date(endDate));
			OutputStream outPut = response.getOutputStream();
			response.setContentType("application/vnd.ms-excel;charset=UTF-8");
			com.broada.apm.entity.ApplicationSystem app = appLogic.queryApplicationsByIds(new String[] {appId}).get(0);
			String appName = "";
			if(app != null){
				appName = app.getName();
			}
			String filename = URLEncoder.encode(appName + "最慢SQL页面排行TOP" + top +".xls", "UTF-8");
			if("FF".equals(getBrowser(request))){
				response.setContentType("application/vnd.ms-excel;charset=ISO-8859-1");
				filename = new String(filename.getBytes("UTF-8"),"ISO-8859-1");
			}
			response.setHeader("Content-Disposition", "attachment; filename=" + filename + ";filename*=UTF-8''" + filename);

			HSSFWorkbook wb = new HSSFWorkbook();  
			HSSFSheet sheet = wb.createSheet("最慢SQL页面排行");

			sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 5));
			Cell cell = sheet.createRow((int) 0).createCell(0);
			cell.setCellValue(appName + "系统最慢SQL页面排行TOP" + top);
			cell.setCellStyle(createCellStyle(wb, 1));

			sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, 5));
			Cell cellt = sheet.createRow((int) 1).createCell(0);
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd");
			cellt.setCellValue(sdf.format(new Date(startDate)) + "-" + sdf.format(new Date(endDate)));
			cellt.setCellStyle(createCellStyle(wb, 2));

			createSqlSlowHead(sheet, 2, createCellStyle(wb, 3));
			createSqlSlowContent(sheet, 4, createCellStyle(wb, 4), perfs);

			wb.write(outPut);
			outPut.close();
		} catch(Exception e){
			log.error("查询性能数据失败：" + e.getMessage());
		}
	}

	@Override
	public void downloadSqlErrorSort(HttpServletRequest request, HttpServletResponse response, String appId, int top,
			long startDate, long endDate) {
		try {
			PerformanceResult result = new PerformanceResult();
			if ("NaN".equals(endDate) || "NaN".equals(startDate)) {
				result.setFailMessage("查询时间错误");
				return ;
			}
			if (StringUtils.isBlank(appId)) {
				result.setFailMessage("未提供系统名称");
				return ;
			}
			if(top == 0){  //默认返回top10
				top = 10;
			}
			List<PerformanceView> perfs = tradePerformanceLogic.getSqlErrorSort(appId, top, new Date(startDate), new Date(endDate));
			OutputStream outPut = response.getOutputStream();
			response.setContentType("application/vnd.ms-excel;charset=UTF-8");
			com.broada.apm.entity.ApplicationSystem app = appLogic.queryApplicationsByIds(new String[] {appId}).get(0);
			String appName = "";
			if(app != null){
				appName = app.getName();
			}
			String filename = URLEncoder.encode(appName + "错误SQL页面排行TOP" + top +".xls", "UTF-8");
			if("FF".equals(getBrowser(request))){
				response.setContentType("application/vnd.ms-excel;charset=ISO-8859-1");
				filename = new String(filename.getBytes("UTF-8"),"ISO-8859-1");
			}
			response.setHeader("Content-Disposition", "attachment; filename=" + filename + ";filename*=UTF-8''" + filename);

			HSSFWorkbook wb = new HSSFWorkbook();  
			HSSFSheet sheet = wb.createSheet("错误SQL页面排行");
			
			sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 3));
			Cell cell = sheet.createRow((int) 0).createCell(0);
			cell.setCellValue(appName + "系统错误SQL页面排行TOP" + top);
			cell.setCellStyle(createCellStyle(wb, 1));

			sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, 3));
			Cell cellt = sheet.createRow((int) 1).createCell(0);
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd");
			cellt.setCellValue(sdf.format(new Date(startDate)) + "-" + sdf.format(new Date(endDate)));
			cellt.setCellStyle(createCellStyle(wb, 2));

			createSqlErrorHead(sheet, 2, createCellStyle(wb, 3));
			createSqlErrorContent(sheet, 4, createCellStyle(wb, 4), perfs);

			wb.write(outPut);
			outPut.close();
		} catch(Exception e){
			log.error("查询性能数据失败：" + e.getMessage());
		}
	}

	/**
	 *  以下为服务器端判断客户端浏览器类型的方法  
	 * @param request
	 * @return
	 */
	private String getBrowser(HttpServletRequest request) {  
		String UserAgent = request.getHeader("USER-AGENT").toLowerCase();  
		if (UserAgent != null) {  
			if (UserAgent.indexOf("msie") >= 0)  
				return "IE";  
			if (UserAgent.indexOf("firefox") >= 0)  
				return "FF";  
			if (UserAgent.indexOf("safari") >= 0)  
				return "SF";  
		}  
		return null;  
	}

	/**
	 * 构造http 慢交易表头
	 * @param sheet
	 * @param startRow
	 * @param styleContent
	 */
	private void createHttpSlowHead(HSSFSheet sheet, int startRow, HSSFCellStyle styleContent){
		int index = 0;
		Row row_title = sheet.createRow(startRow);
		row_title.setHeightInPoints(20);      // 行高
		Cell cell_tmp = row_title.createCell(0);
		cell_tmp.setCellValue("URI");
		cell_tmp.setCellStyle(styleContent);
		index = sheet.addMergedRegion(new CellRangeAddress(startRow, startRow + 1, 0, 0));
		sheet.setColumnWidth(0, 8000);      // uri长度设置宽点
		setRegionStyle(sheet, sheet.getMergedRegion(index), styleContent);
		
		cell_tmp = row_title.createCell(1);
		cell_tmp.setCellValue("站点");
		cell_tmp.setCellStyle(styleContent);
		index = sheet.addMergedRegion(new CellRangeAddress(startRow, startRow + 1, 1, 1));
		sheet.setColumnWidth(1, 8000);      // 站点长度设置宽点
		setRegionStyle(sheet, sheet.getMergedRegion(index), styleContent);
		
		cell_tmp = row_title.createCell(2);
		cell_tmp.setCellValue("平均响应时间\r\n(ms)");
		cell_tmp.setCellStyle(styleContent);
		index = sheet.addMergedRegion(new CellRangeAddress(startRow, startRow + 1, 2, 2));
		sheet.setColumnWidth(2, 4000);     
		setRegionStyle(sheet, sheet.getMergedRegion(index), styleContent);
		
		cell_tmp = row_title.createCell(3);
		cell_tmp.setCellValue("最小\r\n(ms)");
		cell_tmp.setCellStyle(styleContent);
		index = sheet.addMergedRegion(new CellRangeAddress(startRow, startRow + 1, 3, 3));
		sheet.setColumnWidth(3, 4000);   
		setRegionStyle(sheet, sheet.getMergedRegion(index), styleContent);
		
		cell_tmp = row_title.createCell(4);
		cell_tmp.setCellValue("最大\r\n(ms)");
		cell_tmp.setCellStyle(styleContent);
		index = sheet.addMergedRegion(new CellRangeAddress(startRow, startRow + 1, 4, 4));
		sheet.setColumnWidth(4, 4000); 
		setRegionStyle(sheet, sheet.getMergedRegion(index), styleContent);
		
		cell_tmp = row_title.createCell(5);
		cell_tmp.setCellValue("访问次数");
		cell_tmp.setCellStyle(styleContent);
		index = sheet.addMergedRegion(new CellRangeAddress(startRow, startRow + 1, 5, 5));
		sheet.setColumnWidth(5, 4000); 
		setRegionStyle(sheet, sheet.getMergedRegion(index), styleContent);
		
		cell_tmp = row_title.createCell(6);
		cell_tmp.setCellValue("运行总时长\r\n(ms)");
		cell_tmp.setCellStyle(styleContent);
		index = sheet.addMergedRegion(new CellRangeAddress(startRow, startRow + 1, 6, 6));
		sheet.setColumnWidth(6, 4000); 
		setRegionStyle(sheet, sheet.getMergedRegion(index), styleContent);
		
		cell_tmp = row_title.createCell(7);
		cell_tmp.setCellValue("体验好的次数\r\n<1T");
		cell_tmp.setCellStyle(styleContent);
		index = sheet.addMergedRegion(new CellRangeAddress(startRow, startRow + 1, 7, 7));
		sheet.setColumnWidth(7, 4000);  
		setRegionStyle(sheet, sheet.getMergedRegion(index), styleContent);
		
		cell_tmp = row_title.createCell(8);
		cell_tmp.setCellValue("可容忍的次数\r\n1T-4T");
		cell_tmp.setCellStyle(styleContent);
		index = sheet.addMergedRegion(new CellRangeAddress(startRow, startRow + 1, 8, 8));
		sheet.setColumnWidth(8, 4000); 
		setRegionStyle(sheet, sheet.getMergedRegion(index), styleContent);
		
		cell_tmp = row_title.createCell(9);
		cell_tmp.setCellValue("慢的次数\r\n>4T");
		cell_tmp.setCellStyle(styleContent);
		index = sheet.addMergedRegion(new CellRangeAddress(startRow, startRow + 1, 9, 9));
		sheet.setColumnWidth(9, 4000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), styleContent);
	}

	/**
	 * 构建Http慢交易内容
	 * @param sheet
	 * @param startRow
	 * @param styleContent
	 * @param perfs
	 */
	private void createHttpSlowContent(HSSFSheet sheet, int startRow, HSSFCellStyle styleContent, List<PerformanceView> perfs){
		for(int i=0; i<perfs.size(); i++){
			HSSFCellStyle style = createCellStyle(sheet.getWorkbook(), 6);
			PerformanceView pv = perfs.get(i);
			Row rowTmp = sheet.createRow(startRow + i);
			rowTmp.setHeightInPoints(44);
			for(int j=0; j<10; j++){
				Cell cellTmp = rowTmp.createCell(j);
				if(j == 0){
					cellTmp.setCellValue(pv.get("resourceId").toString());
					cellTmp.setCellStyle(style);
				}else if(j ==1){
					cellTmp.setCellValue(pv.get("domainId").toString());
					cellTmp.setCellStyle(style);
				}else if(j ==2){
					cellTmp.setCellValue(pv.get("system/response_time/avg").toString());
					cellTmp.setCellStyle(styleContent);
				}else if(j ==3){
					cellTmp.setCellValue(pv.get("system/response_time/max").toString());
					cellTmp.setCellStyle(styleContent);
				}else if(j ==4){
					cellTmp.setCellValue(pv.get("system/response_time/min").toString());
					cellTmp.setCellStyle(styleContent);
				}else if(j ==5){
					cellTmp.setCellValue((long)Double.parseDouble(pv.get("system/throughput/total").toString()) + "");
					cellTmp.setCellStyle(styleContent);
				}else if(j ==6){
					cellTmp.setCellValue(pv.get("system/response_time/total").toString());
					cellTmp.setCellStyle(styleContent);
				}else if(j ==7){
					cellTmp.setCellValue((long)Double.parseDouble(pv.get("system/apdex/satisfied").toString()) + "");
					cellTmp.setCellStyle(styleContent);
				}else if(j ==8){
					cellTmp.setCellValue((long)Double.parseDouble(pv.get("system/apdex/tolerate").toString()) + "");
					cellTmp.setCellStyle(styleContent);
				}else if(j ==9){
					cellTmp.setCellValue((long)Double.parseDouble(pv.get("system/apdex/slow").toString()) + "");
					cellTmp.setCellStyle(styleContent);
				}
			}
		}
	}

	/**
	 * 构造错误Http表头
	 * @param sheet
	 * @param startRow
	 * @param styleContent
	 */
	private void createHttpErrorHead(HSSFSheet sheet, int startRow, HSSFCellStyle styleContent){
		int index = 0;
		Row row_title = sheet.createRow(startRow);
		Cell cell_tmp = row_title.createCell(0);
		cell_tmp.setCellValue("URI");
		cell_tmp.setCellStyle(styleContent);
		index = sheet.addMergedRegion(new CellRangeAddress(startRow, startRow + 1, 0, 0));
		sheet.setColumnWidth(0, 8000); 
		setRegionStyle(sheet, sheet.getMergedRegion(index), styleContent);
		
		cell_tmp = row_title.createCell(1);
		cell_tmp.setCellValue("站点");
		cell_tmp.setCellStyle(styleContent);
		index = sheet.addMergedRegion(new CellRangeAddress(startRow, startRow + 1, 1, 1));
		sheet.setColumnWidth(1, 6000); 
		setRegionStyle(sheet, sheet.getMergedRegion(index), styleContent);
		
		cell_tmp = row_title.createCell(2);
		cell_tmp.setCellValue("总次数");
		cell_tmp.setCellStyle(styleContent);
		index = sheet.addMergedRegion(new CellRangeAddress(startRow, startRow + 1, 2, 2));
		sheet.setColumnWidth(2, 4000); 
		setRegionStyle(sheet, sheet.getMergedRegion(index), styleContent);
		
		cell_tmp = row_title.createCell(3);
		cell_tmp.setCellValue("成功率%");
		cell_tmp.setCellStyle(styleContent);
		index = sheet.addMergedRegion(new CellRangeAddress(startRow, startRow + 1, 3, 3));
		sheet.setColumnWidth(3, 4000); 
		setRegionStyle(sheet, sheet.getMergedRegion(index), styleContent);
		
		cell_tmp = row_title.createCell(4);
		cell_tmp.setCellValue("3xx");
		cell_tmp.setCellStyle(styleContent);
		index = sheet.addMergedRegion(new CellRangeAddress(startRow, startRow + 1, 4, 4));
		sheet.setColumnWidth(4, 4000); 
		setRegionStyle(sheet, sheet.getMergedRegion(index), styleContent);
		
		cell_tmp = row_title.createCell(5);
		cell_tmp.setCellValue("4xx");
		cell_tmp.setCellStyle(styleContent);
		index = sheet.addMergedRegion(new CellRangeAddress(startRow, startRow + 1, 5, 5));
		sheet.setColumnWidth(5, 4000); 
		setRegionStyle(sheet, sheet.getMergedRegion(index), styleContent);
		
		cell_tmp = row_title.createCell(6);
		cell_tmp.setCellValue("5xx");
		cell_tmp.setCellStyle(styleContent);
		index = sheet.addMergedRegion(new CellRangeAddress(startRow, startRow + 1, 6, 6));
		sheet.setColumnWidth(5, 4000); 
		setRegionStyle(sheet, sheet.getMergedRegion(index), styleContent);
	}
	/**
	 * 构造错误Http内容
	 * @param sheet
	 * @param startRow
	 * @param styleContent
	 * @param perfs
	 */
	private void createHttpErrorContent(HSSFSheet sheet, int startRow, HSSFCellStyle styleContent, List<PerformanceView> perfs){
		for(int i=0; i<perfs.size(); i++){
			HSSFCellStyle style = createCellStyle(sheet.getWorkbook(), 6);
			PerformanceView pv = perfs.get(i);
			Row rowTmp = sheet.createRow(startRow);
			rowTmp.setHeightInPoints(20);
			for(int j=0; j<7; j++){
				Cell cellTmp = rowTmp.createCell(j);
				if(j == 0){
					cellTmp.setCellValue(pv.get("resourceId").toString());
					cellTmp.setCellStyle(style);
				}else if(j == 1){
					cellTmp.setCellValue(pv.get("domainId").toString());
					cellTmp.setCellStyle(style);
				}else if(j == 2){
					cellTmp.setCellValue(pv.get("system/throughput/total").toString());
					cellTmp.setCellStyle(styleContent);
				}else if(j == 3){
					cellTmp.setCellValue(pv.get("system/success/rate").toString());
					cellTmp.setCellStyle(styleContent);
				}else if(j == 4){
					cellTmp.setCellValue(pv.get("3xx").toString());
					cellTmp.setCellStyle(styleContent);
				}else if(j == 5){
					cellTmp.setCellValue(pv.get("4xx").toString());
					cellTmp.setCellStyle(styleContent);
				}else if(j == 6){
					cellTmp.setCellValue(pv.get("5xx").toString());
					cellTmp.setCellStyle(styleContent);
				}
			}
			startRow ++;
		}
	}

	/**
	 * 构造慢SQL表头
	 * @param sheet
	 * @param startRow
	 * @param styleContent
	 */
	private void createSqlSlowHead(HSSFSheet sheet, int startRow, HSSFCellStyle styleContent){
		int index = 0;
		Row row = sheet.createRow(startRow);
		row.setHeightInPoints(20);      // 行高
		for(int i=0; i<6; i++){
			Cell cell = row.createCell(i);
			if(i == 0){
				cell.setCellValue("SQL");
				index = sheet.addMergedRegion(new CellRangeAddress(startRow, startRow + 1, i, i));
				sheet.setColumnWidth(i, 8000); 
			}else if(i == 1){
				cell.setCellValue("平均响应时间\r\n(ms)");
				index = sheet.addMergedRegion(new CellRangeAddress(startRow, startRow + 1, i, i));
				sheet.setColumnWidth(i, 4000); 
			}else if(i == 2){
				cell.setCellValue("最小\r\n(ms)");
				index = sheet.addMergedRegion(new CellRangeAddress(startRow, startRow + 1, i, i));
				sheet.setColumnWidth(i, 4000); 
			}else if(i == 3){
				cell.setCellValue("最大\r\n(ms)");
				index = sheet.addMergedRegion(new CellRangeAddress(startRow, startRow + 1, i, i));
				sheet.setColumnWidth(i, 4000); 
			}else if(i == 4){
				cell.setCellValue("调用次数");
				index = sheet.addMergedRegion(new CellRangeAddress(startRow, startRow + 1, i, i));
				sheet.setColumnWidth(i, 4000); 
			}else if(i == 5){
				cell.setCellValue("运行总时长\r\n(ms)");
				index = sheet.addMergedRegion(new CellRangeAddress(startRow, startRow + 1, i, i));
				sheet.setColumnWidth(i, 4000); 
			}
			setRegionStyle(sheet, sheet.getMergedRegion(index), styleContent);
			cell.setCellStyle(styleContent);
		}
	}

	/**
	 * 构造慢SQL内容
	 * @param sheet
	 * @param startRow
	 * @param styleContent
	 * @param perfs
	 */
	private void createSqlSlowContent(HSSFSheet sheet, int startRow, HSSFCellStyle styleContent, List<PerformanceView> perfs){
		for(int i=0; i<perfs.size(); i++){
			PerformanceView pv = perfs.get(i);
			Row row = sheet.createRow(startRow + i);
			row.setHeightInPoints(44);
			for(int j=0; j<6; j++){
				Cell cell = row.createCell(j);
				if(j == 0){
					cell.setCellValue(pv.get("resourceId").toString());
					cell.setCellStyle(createCellStyle(sheet.getWorkbook(), 6));
				}else if(j == 1){
					cell.setCellValue(pv.get("system/response_time/avg").toString());
					cell.setCellStyle(styleContent);
				}else if(j == 2){
					cell.setCellValue(pv.get("system/response_time/min").toString());
					cell.setCellStyle(styleContent);
				}else if(j == 3){
					cell.setCellValue(pv.get("system/response_time/max").toString());
					cell.setCellStyle(styleContent);
				}else if(j == 4){
					cell.setCellValue(pv.get("system/throughput/total").toString());
					cell.setCellStyle(styleContent);
				}else if(j == 5){
					cell.setCellValue(pv.get("system/response_time/total").toString());
					cell.setCellStyle(styleContent);
				}
			}
		}
	}

	/**
	 * 构造SQL错误表头
	 * @param sheet
	 * @param startRow
	 * @param styleContent
	 */
	private void createSqlErrorHead(HSSFSheet sheet, int startRow, HSSFCellStyle styleContent){
		int index = 0;
		Row row = sheet.createRow(startRow);
		for(int i=0; i<4; i++){
			Cell cell = row.createCell(i);
			if(i == 0){
				cell.setCellValue("SQL");
				index = sheet.addMergedRegion(new CellRangeAddress(startRow, startRow + 1, i, i));
				sheet.setColumnWidth(i, 8000);      // uri长度设置宽点
			}else if(i == 1){
				cell.setCellValue("总次数");
				index = sheet.addMergedRegion(new CellRangeAddress(startRow, startRow + 1, i, i));
				sheet.setColumnWidth(i, 4000);
			}else if(i == 2){
				cell.setCellValue("总错误数");
				index = sheet.addMergedRegion(new CellRangeAddress(startRow, startRow + 1, i, i));
				sheet.setColumnWidth(i, 4000);
			}else if(i == 3){
				cell.setCellValue("成功率%");
				index = sheet.addMergedRegion(new CellRangeAddress(startRow, startRow + 1, i, i));
				sheet.setColumnWidth(i, 4000);
			}
//			else if(i == 4){
//				cell.setCellValue("返回码");
//				index = sheet.addMergedRegion(new CellRangeAddress(startRow, startRow + 1, i, i));
//				sheet.setColumnWidth(i, 4000);
//			}else if(i == 5){
//				cell.setCellValue("错误数");
//				index = sheet.addMergedRegion(new CellRangeAddress(startRow, startRow + 1, i, i));
//				sheet.setColumnWidth(i, 4000);
//			}
			setRegionStyle(sheet, sheet.getMergedRegion(index), styleContent);
			cell.setCellStyle(styleContent);
		}
	}

	/**
	 * 构造sql错误内容
	 * @param sheet
	 * @param startRow
	 * @param styleContent
	 * @param perfs
	 */
	private void createSqlErrorContent(HSSFSheet sheet, int startRow, HSSFCellStyle styleContent, List<PerformanceView> perfs){
		int index = 0;
		for(PerformanceView pv : perfs){
//			List<Map<String, Object>> list = (List<Map<String, Object>>) pv.get("dimensionId");
//			int count = list.size();
			Row rowTmp = sheet.createRow(startRow);
			for(int i=0; i<4; i++){
				if(i == 0){
					Cell cell = rowTmp.createCell(i);
					cell.setCellValue(pv.get("resourceId").toString());
					index = sheet.addMergedRegion(new CellRangeAddress(startRow, startRow, 0, 0));
					setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle(sheet.getWorkbook(), 6));   // 文字居右
				}else if(i == 1){
					Cell cell = rowTmp.createCell(i);
					cell.setCellValue(pv.get("system/throughput/total").toString());
					index = sheet.addMergedRegion(new CellRangeAddress(startRow, startRow, 1, 1));
					setRegionStyle(sheet, sheet.getMergedRegion(index), styleContent);
				}else if(i == 2){
					Cell cell = rowTmp.createCell(i);
					cell.setCellValue(pv.get("system/error/count").toString());
					index = sheet.addMergedRegion(new CellRangeAddress(startRow, startRow, 2, 2));
					setRegionStyle(sheet, sheet.getMergedRegion(index), styleContent);
				}else if(i == 3){
					Cell cell = rowTmp.createCell(i);
					cell.setCellValue(pv.get("system/success/rate").toString());
					index = sheet.addMergedRegion(new CellRangeAddress(startRow, startRow, 3, 3));
					setRegionStyle(sheet, sheet.getMergedRegion(index), styleContent);
				}
//				else{
//					Row row = rowTmp;
//					for(int j=0; j<count; j++){
//						Map<String, Object> map = list.get(j);
//						Cell cell_di = row.createCell(i);
//						cell_di.setCellValue(map.get("dimensionId").toString());
//						cell_di.setCellStyle(styleContent);
//						Cell cell_count = row.createCell(i + 1);
//						cell_count.setCellValue(map.get("count").toString());
//						cell_count.setCellStyle(styleContent);
//						row = sheet.getRow(startRow + j + 1);
//					}
//				}
			}
//			startRow += count;
			startRow ++;
		}
	}
	
	/**
	 * 生成单元格样式
	 * @param wb
	 * @param type
	 * @return
	 */
	private HSSFCellStyle createCellStyle(HSSFWorkbook wb, int type){
		HSSFCellStyle style = null;
		switch(type){
			case 1 :
				// 设置标题样式  
				style = wb.createCellStyle();  
				Font fontTitle = wb.createFont();  
				fontTitle.setBoldweight(Font.BOLDWEIGHT_BOLD); // 粗体  
				fontTitle.setFontHeightInPoints((short)20);
				fontTitle.setFontName("黑体");
				style.setFont(fontTitle);  
				style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 水平居中  
				style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); // 垂直居中;
				break;
			case 2 : 
				// 设置时间样式  
				style = wb.createCellStyle();  
				Font fontTime = wb.createFont();  
				fontTime.setBoldweight(Font.BOLDWEIGHT_BOLD); // 粗体  
				fontTime.setFontHeightInPoints((short)17);
				style.setFont(fontTime);
				style.setAlignment(HSSFCellStyle.ALIGN_RIGHT); // 水平居右 
				style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); // 垂直居中
				break;
			case 3 :
				// 设置列名样式  
				style = wb.createCellStyle();  
				style.setWrapText(true);
				style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
				style.setBorderRight(HSSFCellStyle.BORDER_THIN);
				style.setBorderTop(HSSFCellStyle.BORDER_THIN);
				style.setBorderBottom(HSSFCellStyle.BORDER_THIN);  
				Font font_col = wb.createFont();  
				font_col.setBoldweight(Font.BOLDWEIGHT_BOLD); // 粗体  
				font_col.setFontHeightInPoints((short)12);
				style.setFont(font_col);
				style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 水平居中  
				style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); // 垂直居中
				break;
			case 5 : 
				style = wb.createCellStyle();
				style.setWrapText(true);
				style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
				style.setBorderRight(HSSFCellStyle.BORDER_THIN);
				style.setBorderTop(HSSFCellStyle.BORDER_THIN);
				style.setBorderBottom(HSSFCellStyle.BORDER_THIN);  
				Font font_title = wb.createFont();  
				font_title.setFontHeightInPoints((short)12);
				style.setFont(font_title);
				style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 水平居中
				style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); // 垂直居中
				break;
			case 6 : 
				style = wb.createCellStyle();
				style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
				style.setBorderRight(HSSFCellStyle.BORDER_THIN);
				style.setBorderTop(HSSFCellStyle.BORDER_THIN);
				style.setBorderBottom(HSSFCellStyle.BORDER_THIN);  
				Font _title = wb.createFont();  
				_title.setFontHeightInPoints((short)12);
				style.setFont(_title);
				style.setAlignment(HSSFCellStyle.ALIGN_LEFT); // 水平居左
				style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); // 垂直居中
				break;
			default :
				style = wb.createCellStyle();
				style.setWrapText(true);
				style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
				style.setBorderRight(HSSFCellStyle.BORDER_THIN);
				style.setBorderTop(HSSFCellStyle.BORDER_THIN);
				style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
				Font font_content = wb.createFont();  
				font_content.setFontHeightInPoints((short)12);
				style.setFont(font_content);
				style.setAlignment(HSSFCellStyle.ALIGN_RIGHT); // 水平居右
				style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); // 垂直居中
		}
		return style;
	}

	@Override
	public void downloadSystemAvailability(HttpServletRequest request, HttpServletResponse response, long startDate,
			long endDate) {
		try {
			PerformanceResult result = new PerformanceResult();
			if ("NaN".equals(endDate) || "NaN".equals(startDate)) {
				result.setFailMessage("查询时间错误");
				return ;
			}
			@SuppressWarnings("unchecked")
			List<PerformanceView> perfs = (List<PerformanceView>) querySystemAvailability(startDate, endDate).get(Constants.PERFORMANCES);
			String filename = URLEncoder.encode("系统可用性报表.xls", "UTF-8");
			OutputStream outPut = response.getOutputStream();
			response.setContentType("application/vnd.ms-excel;charset=UTF-8");
			if("FF".equals(getBrowser(request))){
				response.setContentType("application/vnd.ms-excel;charset=ISO-8859-1");
				filename = new String(filename.getBytes("UTF-8"),"ISO-8859-1");
			}
			response.setHeader("Content-Disposition", "attachment; filename=" + filename + ";filename*=UTF-8''" + filename);

			HSSFWorkbook wb = new HSSFWorkbook();  
			HSSFSheet sheet = wb.createSheet("系统可用性报表");

			sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 9));
			Cell cell = sheet.createRow((int) 0).createCell(0);
			cell.setCellValue("系统可用性报表");
			cell.setCellStyle(createCellStyle(wb, 1));

			sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, 9));
			Cell cellt = sheet.createRow((int) 1).createCell(0);
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd");
			cellt.setCellValue(sdf.format(new Date(startDate)) + "-" + sdf.format(new Date(endDate)));
			cellt.setCellStyle(createCellStyle(wb, 2));

			createSystemAvailabilityHead(sheet, 2, createCellStyle(wb, 3));
			createSystemAvailabilityContent(sheet, 4, createCellStyle(wb, 4), perfs);

			wb.write(outPut);
			outPut.close();
		} catch(Exception e){
			log.error("查询性能数据失败：" + e.getMessage());
		}	
	}
	
	private void createSystemAvailabilityHead(HSSFSheet sheet, int startRow, HSSFCellStyle styleContent){
		int index = 0;
		Row row_col = sheet.createRow(startRow);
		Cell col_0 = row_col.createCell(0);
		row_col.setHeightInPoints(20);
		col_0.setCellValue("系统名称");
		col_0.setCellStyle(styleContent);
		index = sheet.addMergedRegion(new CellRangeAddress(2, 3, 0, 0));
		sheet.setColumnWidth(0, 8000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), styleContent);
		
		Cell col_1 = row_col.createCell(1);
		col_1.setCellValue("系统可用性");
		col_1.setCellStyle(styleContent);
		index = sheet.addMergedRegion(new CellRangeAddress(2, 2, 1, 4));
		sheet.setColumnWidth(1, 8000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), styleContent);
		
		Cell col_11 = row_col.createCell(5);
		col_11.setCellValue("交易成功率");
		col_11.setCellStyle(styleContent);
		index = sheet.addMergedRegion(new CellRangeAddress(2, 2, 5, 9));
		sheet.setColumnWidth(2, 8000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), styleContent);
		
//		Row row_col3 = sheet.createRow(3);
		Row row_col3 = sheet.getRow(3);
		row_col3.setHeightInPoints(30);
		Cell col_2 = row_col3.createCell(1);
		col_2.setCellValue("可用率%");
		col_2.setCellStyle(styleContent);
		index = sheet.addMergedRegion(new CellRangeAddress(3, 3, 1, 1));
		sheet.setColumnWidth(3, 4000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), styleContent);
		
		Cell col_3 = row_col3.createCell(2);
		col_3.setCellValue("提供服务总时间\r\n（分钟）");
		col_3.setCellStyle(styleContent);
		index = sheet.addMergedRegion(new CellRangeAddress(3, 3, 2, 2));
		sheet.setColumnWidth(4, 4000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), styleContent);
		
		Cell col_4 = row_col3.createCell(3);
		col_4.setCellValue("服务中断时间\r\n（分钟）");
		col_4.setCellStyle(styleContent);
		index = sheet.addMergedRegion(new CellRangeAddress(3, 3, 3, 3));
		sheet.setColumnWidth(5, 4000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), styleContent);
		
		Cell col_5 = row_col3.createCell(4);
		col_5.setCellValue("服务中断次数");
		col_5.setCellStyle(styleContent);
		index = sheet.addMergedRegion(new CellRangeAddress(3, 3, 4, 4));
		sheet.setColumnWidth(6, 4000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), styleContent);
		
		Cell col_6 = row_col3.createCell(5);
		col_6.setCellValue("交易总量");
		col_6.setCellStyle(styleContent);
		index = sheet.addMergedRegion(new CellRangeAddress(3, 3, 5, 5));
		sheet.setColumnWidth(7, 4000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), styleContent);
		
		Cell col_7 = row_col3.createCell(6);
		col_7.setCellValue("成功交易量");
		col_7.setCellStyle(styleContent);
		index = sheet.addMergedRegion(new CellRangeAddress(3, 3, 6, 6));
		sheet.setColumnWidth(8, 4000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), styleContent);
		
		Cell col_8 = row_col3.createCell(7);
		col_8.setCellValue("成功率%");
		col_8.setCellStyle(styleContent);
		index = sheet.addMergedRegion(new CellRangeAddress(3, 3, 7, 7));
		sheet.setColumnWidth(9, 4000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), styleContent);
		
		Cell col_9 = row_col3.createCell(8);
		col_9.setCellValue("上期交易量");
		col_9.setCellStyle(styleContent);
		index = sheet.addMergedRegion(new CellRangeAddress(3, 3, 8, 8));
		sheet.setColumnWidth(10, 4000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), styleContent);
		
		Cell col_10 = row_col3.createCell(9);
		col_10.setCellValue("变化率");
		col_10.setCellStyle(styleContent);
		index = sheet.addMergedRegion(new CellRangeAddress(3, 3, 9, 9));
		sheet.setColumnWidth(11, 4000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), styleContent);
	}
	
	private void createSystemAvailabilityContent(HSSFSheet sheet, int startRow, HSSFCellStyle styleContent, List<PerformanceView> perfs){
		for(int i=0; i<perfs.size(); i++){
			PerformanceView pv = perfs.get(i);
			Row rowTmp = sheet.createRow(startRow + i);
			for(int j=0; j<10; j++){
				Cell cellTmp = rowTmp.createCell(j);
				if(j == 0){
					cellTmp.setCellValue(pv.get("appName").toString());
					cellTmp.setCellStyle(createCellStyle(sheet.getWorkbook(), 6));   // 文字靠左
				}else if(j ==1){
					cellTmp.setCellValue(pv.get("appAvailableRate").toString());
					cellTmp.setCellStyle(styleContent);
				}else if(j ==2){
					cellTmp.setCellValue(pv.get("appServerTime").toString());
					cellTmp.setCellStyle(styleContent);
				}else if(j ==3){
					cellTmp.setCellValue(pv.get("appInterruptTime").toString());
					cellTmp.setCellStyle(styleContent);
				}else if(j ==4){
					cellTmp.setCellValue(pv.get("appInterruptCount").toString());
					cellTmp.setCellStyle(styleContent);
				}else if(j ==5){
					cellTmp.setCellValue(pv.get("business/throughput/total").toString());
					cellTmp.setCellStyle(styleContent);
				}else if(j ==6){
					cellTmp.setCellValue(pv.get("business/success/count").toString());
					cellTmp.setCellStyle(styleContent);
				}else if(j ==7){
					cellTmp.setCellValue(pv.get("business/success/rate").toString());
					cellTmp.setCellStyle(styleContent);
				}else if(j ==8){
					cellTmp.setCellValue(pv.get("history_business/throughput/total").toString());
					cellTmp.setCellStyle(styleContent);
				}else if(j ==9){
					cellTmp.setCellValue(pv.get("business/throughput/total_rate").toString());
					cellTmp.setCellStyle(styleContent);
				}
			}
		}
	}

	@Override
	public void downloadSystemFault(HttpServletRequest request, HttpServletResponse response, long startDate,
			long endDate) {
		try {
			PerformanceResult result = new PerformanceResult();
			if ("NaN".equals(endDate) || "NaN".equals(startDate)) {
				result.setFailMessage("查询时间错误");
				return ;
			}
			@SuppressWarnings("unchecked")
			List<PerformanceView> perfs = (List<PerformanceView>) querySystemFault(startDate, endDate).get(Constants.PERFORMANCES);
			String filename = URLEncoder.encode("系统故障报表.xls", "UTF-8");
			OutputStream outPut = response.getOutputStream();
			response.setContentType("application/vnd.ms-excel;charset=UTF-8");
			if("FF".equals(getBrowser(request))){
				response.setContentType("application/vnd.ms-excel;charset=ISO-8859-1");
				filename = new String(filename.getBytes("UTF-8"),"ISO-8859-1");
			}
			response.setHeader("Content-Disposition", "attachment; filename=" + filename + ";filename*=UTF-8''" + filename);

			HSSFWorkbook wb = new HSSFWorkbook();  
			HSSFSheet sheet = wb.createSheet("系统故障报表");

			sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 14));
			Cell cell = sheet.createRow((int) 0).createCell(0);
			cell.setCellValue("系统故障报表");
			cell.setCellStyle(createCellStyle(wb, 1));

			sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, 14));
			Cell cellt = sheet.createRow((int) 1).createCell(0);
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd");
			cellt.setCellValue(sdf.format(new Date(startDate)) + "-" + sdf.format(new Date(endDate)));
			cellt.setCellStyle(createCellStyle(wb, 2));

			createSystemFaultHead(sheet, 2, createCellStyle(wb, 3));
			createSystemFaultContent(sheet, 4, createCellStyle(wb, 4), perfs);

			wb.write(outPut);
			outPut.close();
		} catch(Exception e){
			log.error("查询性能数据失败：" + e.getMessage());
		}	
	}

	private void createSystemFaultContent(HSSFSheet sheet, int startRow, HSSFCellStyle styleContent,
			List<PerformanceView> perfs) {
		HSSFCellStyle style_right = createCellStyle(sheet.getWorkbook(), 6);   // 文字居左
		for (PerformanceView perf : perfs) {
			int index = 0;
			@SuppressWarnings("unchecked")
			List<Map<String, Object>> list = (List<Map<String, Object>>) perf.get("service");
			int count = list.size();
			Row rowTmp = sheet.createRow(startRow);
			for (int i=0; i<2; i++) {
				Cell cell = rowTmp.createCell(i);
				if (i == 0) {
					cell.setCellValue(perf.get("appName").toString());
					cell.setCellStyle(style_right);
					index = sheet.addMergedRegion(new CellRangeAddress(startRow, startRow + count, 0, 0));
					setRegionStyle(sheet, sheet.getMergedRegion(index), style_right);
				} else {
					Cell total_title = rowTmp.createCell(i);
					total_title.setCellValue("合计");
					total_title.setCellStyle(style_right);
					Cell cell_50_count = rowTmp.createCell(i + 1);
					cell_50_count.setCellValue(perf.get("50Count").toString());
					cell_50_count.setCellStyle(styleContent);
					Cell cell_20_count = rowTmp.createCell(i + 2);
					cell_20_count.setCellValue(perf.get("20Count").toString());
					cell_20_count.setCellStyle(styleContent);
					Cell cell_10_count = rowTmp.createCell(i + 3);
					cell_10_count.setCellValue(perf.get("10Count").toString());
					cell_10_count.setCellStyle(styleContent);
					Cell cell_brpm = rowTmp.createCell(i + 4);
					cell_brpm.setCellValue(perf.get("brpmCount").toString());
					cell_brpm.setCellStyle(styleContent);
					Cell cell_brtt = rowTmp.createCell(i + 5);
					cell_brtt.setCellValue(perf.get("brttCount").toString());
					cell_brtt.setCellStyle(styleContent);
					Cell cell_bsuccess = rowTmp.createCell(i + 6);
					cell_bsuccess.setCellValue(perf.get("bsuccessCount").toString());
					cell_bsuccess.setCellStyle(styleContent);
					Cell cell_berror = rowTmp.createCell(i + 7);
					cell_berror.setCellValue(perf.get("berrorCount").toString());
					cell_berror.setCellStyle(styleContent);
					Cell cell_bapdex = rowTmp.createCell(i + 8);
					cell_bapdex.setCellValue(perf.get("bapdexCount").toString());
					cell_bapdex.setCellStyle(styleContent);
					Cell cell_rpm = rowTmp.createCell(i + 9);
					cell_rpm.setCellValue(perf.get("rpmCount").toString());
					cell_rpm.setCellStyle(styleContent);
					Cell cell_rtt = rowTmp.createCell(i + 10);
					cell_rtt.setCellValue(perf.get("rttCount").toString());
					cell_rtt.setCellStyle(styleContent);
					Cell cell_success = rowTmp.createCell(i + 11);
					cell_success.setCellValue(perf.get("successCount").toString());
					cell_success.setCellStyle(styleContent);
					Cell cell_error = rowTmp.createCell(i + 12);
					cell_error.setCellValue(perf.get("errorCount").toString());
					cell_error.setCellStyle(styleContent);
					Cell cell_apdex = rowTmp.createCell(i + 13);
					cell_apdex.setCellValue(perf.get("apdexCount").toString());
					cell_apdex.setCellStyle(styleContent);
					for (int j=0; j<list.size(); j++) {
						Map<String, Object> map = list.get(j);
//						Row row = sheet.createRow(startRow + 1 + j);
						Row row = sheet.getRow(startRow + 1 + j);
						Cell cell_name = row.createCell(i);
						cell_name.setCellValue(map.get("serviceName").toString());
						cell_name.setCellStyle(style_right);
						Cell cell_50_count1 = row.createCell(i + 1);
						cell_50_count1.setCellValue(map.get("50Count").toString());
						cell_50_count1.setCellStyle(styleContent);
						Cell cell_20_count1 = row.createCell(i + 2);
						cell_20_count1.setCellValue(map.get("20Count").toString());
						cell_20_count1.setCellStyle(styleContent);
						Cell cell_10_count1 = row.createCell(i + 3);
						cell_10_count1.setCellValue(map.get("10Count").toString());
						cell_10_count1.setCellStyle(styleContent);
						Cell cell_brpm1 = row.createCell(i + 4);
						cell_brpm1.setCellValue(map.get("brpmCount").toString());
						cell_brpm1.setCellStyle(styleContent);
						Cell cell_brtt1 = row.createCell(i + 5);
						cell_brtt1.setCellValue(map.get("brttCount").toString());
						cell_brtt1.setCellStyle(styleContent);
						Cell cell_bsuccess1 = row.createCell(i + 6);
						cell_bsuccess1.setCellValue(map.get("bsuccessCount").toString());
						cell_bsuccess1.setCellStyle(styleContent);
						Cell cell_berror1 = row.createCell(i + 7);
						cell_berror1.setCellValue(map.get("berrorCount").toString());
						cell_berror1.setCellStyle(styleContent);
						Cell cell_bapdex1 = row.createCell(i + 8);
						cell_bapdex1.setCellValue(map.get("bapdexCount").toString());
						cell_bapdex1.setCellStyle(styleContent);
						Cell cell_rpm1 = row.createCell(i + 9);
						cell_rpm1.setCellValue(map.get("rpmCount").toString());
						cell_rpm1.setCellStyle(styleContent);
						Cell cell_rtt1 = row.createCell(i + 10);
						cell_rtt1.setCellValue(map.get("rttCount").toString());
						cell_rtt1.setCellStyle(styleContent);
						Cell cell_success1 = row.createCell(i + 11);
						cell_success1.setCellValue(map.get("successCount").toString());
						cell_success1.setCellStyle(styleContent);
						Cell cell_error1 = row.createCell(i + 12);
						cell_error1.setCellValue(map.get("errorCount").toString());
						cell_error1.setCellStyle(styleContent);
						Cell cell_apdex1 = row.createCell(i + 13);
						cell_apdex1.setCellValue(map.get("apdexCount").toString());
						cell_apdex1.setCellStyle(styleContent);
					}
				}
			}
			startRow += (count + 1);
		}
	}

	private void createSystemFaultHead(HSSFSheet sheet, int startRow, HSSFCellStyle createCellStyle) {
		int index = 0;
		Row row_col = sheet.createRow(startRow);
		Cell col_0 = row_col.createCell(0);
		row_col.setHeightInPoints(20);
		col_0.setCellValue("系统名称");
		col_0.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(2, 3, 0, 0));
		sheet.setColumnWidth(0, 8000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell col_1 = row_col.createCell(1);
		col_1.setCellValue("服务器");
		col_1.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(2, 3, 1, 1));
		sheet.setColumnWidth(1, 8000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell col_2 = row_col.createCell(2);
		col_2.setCellValue("告警数");
		col_2.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(2, 2, 2, 4));
		sheet.setColumnWidth(2, 8000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell col_3 = row_col.createCell(5);
		col_3.setCellValue("交易告警");
		col_3.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(2, 2, 5, 9));
		sheet.setColumnWidth(5, 8000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell col_4 = row_col.createCell(10);
		col_4.setCellValue("应用系统告警");
		col_4.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(2, 2, 10, 14));
		sheet.setColumnWidth(10, 8000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
//		Row row_col1 = sheet.createRow(3);
		Row row_col1 = sheet.getRow(3);
		row_col1.setHeightInPoints(20);
		Cell col_11 = row_col1.createCell(2);
		col_11.setCellValue("严重");
		col_11.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(3, 3, 2, 2));
		sheet.setColumnWidth(2, 3000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell col_12 = row_col1.createCell(3);
		row_col1.setHeightInPoints(20);
		col_12.setCellValue("警告");
		col_12.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(3, 3, 3, 3));
		sheet.setColumnWidth(3, 3000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell col_13 = row_col1.createCell(4);
		row_col1.setHeightInPoints(20);
		col_13.setCellValue("提醒");
		col_13.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(3, 3, 4, 4));
		sheet.setColumnWidth(4, 3000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell col_14 = row_col1.createCell(5);
		row_col1.setHeightInPoints(20);
		col_14.setCellValue("交易量告警");
		col_14.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(3, 3, 5, 5));
		sheet.setColumnWidth(5, 4500);
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell col_15 = row_col1.createCell(6);
		row_col1.setHeightInPoints(20);
		col_15.setCellValue("响应时间告警");
		col_15.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(3, 3, 6, 6));
		sheet.setColumnWidth(6, 4500);
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell col_16 = row_col1.createCell(7);
		row_col1.setHeightInPoints(20);
		col_16.setCellValue("成功率告警");
		col_16.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(3, 3, 7, 7));
		sheet.setColumnWidth(7, 4500);
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell col_17 = row_col1.createCell(8);
		row_col1.setHeightInPoints(20);
		col_17.setCellValue("错误数告警");
		col_17.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(3, 3, 8, 8));
		sheet.setColumnWidth(8, 4500);
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell col_18 = row_col1.createCell(9);
		row_col1.setHeightInPoints(20);
		col_18.setCellValue("Apdex告警");
		col_18.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(3, 3, 9, 9));
		sheet.setColumnWidth(9, 4500);
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell col_19 = row_col1.createCell(10);
		row_col1.setHeightInPoints(20);
		col_19.setCellValue("吞吐量告警");
		col_19.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(3, 3, 10, 10));
		sheet.setColumnWidth(10, 4500);
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell col_20 = row_col1.createCell(11);
		row_col1.setHeightInPoints(20);
		col_20.setCellValue("响应时间告警");
		col_20.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(3, 3, 11, 11));
		sheet.setColumnWidth(11, 4500);
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell col_21 = row_col1.createCell(12);
		row_col1.setHeightInPoints(20);
		col_21.setCellValue("成功率告警");
		col_21.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(3, 3, 12, 12));
		sheet.setColumnWidth(12, 4500);
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell col_22 = row_col1.createCell(13);
		row_col1.setHeightInPoints(20);
		col_22.setCellValue("错误数告警");
		col_22.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(3, 3, 13, 13));
		sheet.setColumnWidth(13, 4500);
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell col_23 = row_col1.createCell(14);
		row_col1.setHeightInPoints(20);
		col_23.setCellValue("Apdex告警");
		col_23.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(3, 3, 14, 14));
		sheet.setColumnWidth(14, 4500);
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
	}

	@Override
	public void downloadTradePerf(HttpServletRequest request, HttpServletResponse response, String appId,
			long startDate, long endDate) {
		try {
			PerformanceResult result = new PerformanceResult();
			if ("NaN".equals(endDate) || "NaN".equals(startDate)) {
				result.setFailMessage("查询时间错误");
				return ;
			}
			@SuppressWarnings("unchecked")
			List<PerformanceView> perfs = (List<PerformanceView>) queryTradeTypePerf(appId, startDate, endDate).get(Constants.PERFORMANCES);
			String filename = URLEncoder.encode("关键交易性能报表.xls", "UTF-8");
			OutputStream outPut = response.getOutputStream();
			response.setContentType("application/vnd.ms-excel;charset=UTF-8");
			com.broada.apm.entity.ApplicationSystem app = appLogic.queryApplicationsByIds(new String[] {appId}).get(0);
			String appName = "";
			if(app != null){
				appName = app.getName();
			}
			if("FF".equals(getBrowser(request))){
				response.setContentType("application/vnd.ms-excel;charset=ISO-8859-1");
				filename = new String(filename.getBytes("UTF-8"),"ISO-8859-1");
			}
			response.setHeader("Content-Disposition", "attachment; filename=" + filename + ";filename*=UTF-8''" + filename);

			HSSFWorkbook wb = new HSSFWorkbook();  
			HSSFSheet sheet = wb.createSheet("关键交易性能报表");

			sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 10));
			Cell cell = sheet.createRow((int) 0).createCell(0);
			cell.setCellValue(appName + "关键交易性能报表");
			cell.setCellStyle(createCellStyle(wb, 1));

			sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, 10));
			Cell cellt = sheet.createRow((int) 1).createCell(0);
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd");
			cellt.setCellValue(sdf.format(new Date(startDate)) + "-" + sdf.format(new Date(endDate)));
			cellt.setCellStyle(createCellStyle(wb, 2));

			createTradeTypePerfHead(sheet, 2, createCellStyle(wb, 3));
			createTradeTypePerfContent(sheet, 4, createCellStyle(wb, 4), perfs);

			wb.write(outPut);
			outPut.close();
		} catch(Exception e){
			log.error("查询性能数据失败：" + e.getMessage());
		}	
		
	}

	private void createTradeTypePerfContent(HSSFSheet sheet, int startRow, HSSFCellStyle styleContent,
			List<PerformanceView> perfs) {
		for(int i=0; i<perfs.size(); i++){
			int index = 0;
			PerformanceView perfView = perfs.get(i);
			@SuppressWarnings("unchecked")
			List<Map<String, Object>> list = (List<Map<String, Object>>) perfView.get("channel");
			int count = list.size();    // 多少行合并
			Row rowTmp = sheet.createRow(startRow);
			HSSFCellStyle style = createCellStyle(sheet.getWorkbook(), 6);
			for (int j=0; j<3; j++) {
				Cell cellTmp = rowTmp.createCell(j);
				if (j == 0) {
					cellTmp.setCellValue(perfView.get("typeName").toString());
					cellTmp.setCellStyle(style);
					index = sheet.addMergedRegion(new CellRangeAddress(startRow, startRow + count, j, j));
					setRegionStyle(sheet, sheet.getMergedRegion(index), style);
				} else if (j == 1) {
					cellTmp.setCellValue(perfView.get("serviceName").toString());
					cellTmp.setCellStyle(style);
					index = sheet.addMergedRegion(new CellRangeAddress(startRow, startRow + count, j, j));
					setRegionStyle(sheet, sheet.getMergedRegion(index), style);
				} else if (j == 2) {
					Cell total_title = rowTmp.createCell(j);
					total_title.setCellValue("合计");
					total_title.setCellStyle(style);
					Cell business_throughtput_count = rowTmp.createCell(j+1);
					business_throughtput_count.setCellValue(perfView.get("count").toString());
					business_throughtput_count.setCellStyle(styleContent);
					Cell business_throughput_sequential_rate = rowTmp.createCell(j+2);
					business_throughput_sequential_rate.setCellValue(perfView.get("business/throughput/sequential_rate") == null ? "-" : perfView.get("business/throughput/sequential_rate").toString());
					business_throughput_sequential_rate.setCellStyle(styleContent);
					Cell response_time = rowTmp.createCell(j+3);
					response_time.setCellValue(perfView.get("responseTime").toString());
					response_time.setCellStyle(styleContent);
					Cell response_time_sequential_rate = rowTmp.createCell(j+4);
					response_time_sequential_rate.setCellValue(perfView.get("business/response_time/sequential_rate") == null ? "-" : perfView.get("business/response_time/sequential_rate").toString());
					response_time_sequential_rate.setCellStyle(styleContent);
					Cell success_rate = rowTmp.createCell(j+5);
					success_rate.setCellValue(perfView.get("success_rate").toString());
					success_rate.setCellStyle(styleContent);
					Cell success_sequential_rate = rowTmp.createCell(j+6);
					success_sequential_rate.setCellValue(perfView.get("business/success/sequential_rate") == null ? "-" : perfView.get("business/success/sequential_rate").toString());
					success_sequential_rate.setCellStyle(styleContent);
					Cell error_count = rowTmp.createCell(j+7);
					error_count.setCellValue(perfView.get("isError").toString());
					error_count.setCellStyle(styleContent);
					Cell error_count_sequential_rate = rowTmp.createCell(j+8);
					error_count_sequential_rate.setCellValue(perfView.get("business/error_count/sequential_rate") == null ? "-" : perfView.get("business/error_count/sequential_rate").toString());
					error_count_sequential_rate.setCellStyle(styleContent);
					
					for(int k=0; k<list.size(); k++){
//						Row row = sheet.createRow(startRow + 1 + k);
						Row row = sheet.getRow(startRow + 1 + k);
						Map<String, Object> map = list.get(k);
						Cell total_title1 = row.createCell(j);
						total_title1.setCellValue(map.get("channelName").toString());
						total_title1.setCellStyle(style);
						Cell business_throughtput_count1 = row.createCell(j+1);
						business_throughtput_count1.setCellValue(map.get("count").toString());
						business_throughtput_count1.setCellStyle(styleContent);
						Cell business_throughput_sequential_rate1 = row.createCell(j+2);
						business_throughput_sequential_rate1.setCellValue(map.get("business/throughput/sequential_rate") == null ? "-" : map.get("business/throughput/sequential_rate").toString());
						business_throughput_sequential_rate1.setCellStyle(styleContent);
						Cell response_time1 = row.createCell(j+3);
						response_time1.setCellValue(map.get("responseTime").toString());
						response_time1.setCellStyle(styleContent);
						Cell response_time_sequential_rate1 = row.createCell(j+4);
						response_time_sequential_rate1.setCellValue(map.get("business/response_time/sequential_rate") == null ? "-" : map.get("business/response_time/sequential_rate").toString());
						response_time_sequential_rate1.setCellStyle(styleContent);
						Cell success_rate1 = row.createCell(j+5);
						success_rate1.setCellValue(map.get("success_rate").toString());
						success_rate1.setCellStyle(styleContent);
						Cell success_sequential_rate1 = row.createCell(j+6);
						success_sequential_rate1.setCellValue(map.get("business/success/sequential_rate") == null ? "-" : map.get("business/success/sequential_rate").toString());
						success_sequential_rate1.setCellStyle(styleContent);
						Cell error_count1 = row.createCell(j+7);
						error_count1.setCellValue(map.get("isError").toString());
						error_count1.setCellStyle(styleContent);
						Cell error_count_sequential_rate1 = row.createCell(j+8);
						error_count_sequential_rate1.setCellValue(map.get("business/error_count/sequential_rate") == null ? "-" : map.get("business/error_count/sequential_rate").toString());
						error_count_sequential_rate1.setCellStyle(styleContent);
					}
				}
			}
			startRow += (count + 1);
		}
		
	}

	private void createTradeTypePerfHead(HSSFSheet sheet, int startRow, HSSFCellStyle createCellStyle) {
		int index = 0;
		Row row_col = sheet.createRow(startRow);
		Cell col_0 = row_col.createCell(0);
		row_col.setHeightInPoints(48);
		col_0.setCellValue("交易名称");
		col_0.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(2, 3, 0, 0));
		sheet.setColumnWidth(0, 8000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell col_1 = row_col.createCell(1);
		col_1.setCellValue("服务节点");
		col_1.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(2, 3, 1, 1));
		sheet.setColumnWidth(1, 8000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell col_2 = row_col.createCell(2);
		col_2.setCellValue("渠道");
		col_2.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(2, 3, 2, 2));
		sheet.setColumnWidth(2, 8000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell col_3 = row_col.createCell(3);
		col_3.setCellValue("交易量");
		col_3.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(2, 2, 3, 4));
		sheet.setColumnWidth(3, 6000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell col_4 = row_col.createCell(5);
		col_4.setCellValue("平均响应时间\r\n(ms)");
		col_4.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(2, 2, 5, 6));
		sheet.setColumnWidth(4, 6000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell col_5 = row_col.createCell(7);
		col_5.setCellValue("成功率%");
		col_5.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(2, 2, 7, 8));
		sheet.setColumnWidth(5, 6000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell col_6 = row_col.createCell(9);
		col_6.setCellValue("错误数");
		col_6.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(2, 2, 9, 10));
		sheet.setColumnWidth(6, 6000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
//		Row row_col1 = sheet.createRow(3);
		Row row_col1 = sheet.getRow(3);
		row_col1.setHeightInPoints(20);
		Cell col_10 = row_col1.createCell(3);
		col_10.setCellValue("本期");
		col_10.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(3, 3, 3, 3));
		sheet.setColumnWidth(7, 3000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell col_11 = row_col1.createCell(4);
		col_11.setCellValue("环比%");
		col_11.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(3, 3, 4, 4));
		sheet.setColumnWidth(8, 3000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell col_12 = row_col1.createCell(5);
		col_12.setCellValue("本期");
		col_12.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(3, 3, 5, 5));
		sheet.setColumnWidth(9, 3000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell col_13 = row_col1.createCell(6);
		col_13.setCellValue("环比%");
		col_13.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(3, 3, 6, 6));
		sheet.setColumnWidth(10, 3000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell col_14 = row_col1.createCell(7);
		col_14.setCellValue("本期");
		col_14.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(3, 3, 7, 7));
		sheet.setColumnWidth(11, 3000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell col_15 = row_col1.createCell(8);
		col_15.setCellValue("环比%");
		col_15.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(3, 3, 8, 8));
		sheet.setColumnWidth(12, 3000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell col_16 = row_col1.createCell(9);
		col_16.setCellValue("本期");
		col_16.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(3, 3, 9, 9));
		sheet.setColumnWidth(13, 3000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell col_17 = row_col1.createCell(10);
		col_17.setCellValue("环比%");
		col_17.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(3, 3, 10, 10));
		sheet.setColumnWidth(14, 3000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
	}

	@Override
	public void downloadTradeSort(HttpServletRequest request, HttpServletResponse response, int top, long startDate,
			long endDate) {
		try {
			PerformanceResult result = new PerformanceResult();
			if ("NaN".equals(endDate) || "NaN".equals(startDate)) {
				result.setFailMessage("查询时间错误");
				return ;
			}
			@SuppressWarnings("unchecked")
			List<PerformanceView> perfs = (List<PerformanceView>) queryTradeTypeSort(top == 0 ? Integer.MAX_VALUE : top, startDate, endDate).get(Constants.PERFORMANCES);
			String filename = URLEncoder.encode("交易量总排行报表.xls", "UTF-8");
			OutputStream outPut = response.getOutputStream();
			response.setContentType("application/vnd.ms-excel;charset=UTF-8");
			if("FF".equals(getBrowser(request))){
				response.setContentType("application/vnd.ms-excel;charset=ISO-8859-1");
				filename = new String(filename.getBytes("UTF-8"),"ISO-8859-1");
			}
			response.setHeader("Content-Disposition", "attachment; filename=" + filename + ";filename*=UTF-8''" + filename);

			HSSFWorkbook wb = new HSSFWorkbook();  
			HSSFSheet sheet = wb.createSheet("关键交易性能报表");

			sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 7));
			Cell cell = sheet.createRow((int) 0).createCell(0);
			cell.setCellValue("交易量总排行报表");
			cell.setCellStyle(createCellStyle(wb, 1));

			sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, 7));
			Cell cellt = sheet.createRow((int) 1).createCell(0);
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd");
			cellt.setCellValue(sdf.format(new Date(startDate)) + "-" + sdf.format(new Date(endDate)));
			cellt.setCellStyle(createCellStyle(wb, 2));

			createTradeTypeSortHead(sheet, 2, createCellStyle(wb, 3));
			createTradeTypeSortContent(sheet, 4, createCellStyle(wb, 4), perfs);

			wb.write(outPut);
			outPut.close();
		} catch(Exception e){
			log.error("查询性能数据失败：" + e.getMessage());
		}	
		
	}

	private void createTradeTypeSortHead(HSSFSheet sheet, int startRow, HSSFCellStyle createCellStyle) {
		int index = 0;
		Row row_col = sheet.createRow(startRow);
		Cell col_0 = row_col.createCell(0);
		row_col.setHeightInPoints(20);
		col_0.setCellValue("交易名称");
		col_0.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(2, 3, 0, 0));
		sheet.setColumnWidth(0, 8000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell col_1 = row_col.createCell(1);
		col_1.setCellValue("业务系统");
		col_1.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(2, 3, 1, 1));
		sheet.setColumnWidth(1, 8000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell col_2 = row_col.createCell(2);
		col_2.setCellValue("服务节点");
		col_2.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(2, 3, 2, 2));
		sheet.setColumnWidth(2, 8000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell col_3 = row_col.createCell(3);
		col_3.setCellValue("渠道");
		col_3.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(2, 3, 3, 3));
		sheet.setColumnWidth(3, 8000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell col_4 = row_col.createCell(4);
		col_4.setCellValue("交易量");
		col_4.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(2, 3, 4, 4));
		sheet.setColumnWidth(4, 8000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell col_5 = row_col.createCell(5);
		col_5.setCellValue("平均响应时间\r\n(ms)");
		col_5.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(2, 3, 5, 5));
		sheet.setColumnWidth(5, 8000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell col_6 = row_col.createCell(6);
		col_6.setCellValue("成功率%");
		col_6.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(2, 3, 6, 6));
		sheet.setColumnWidth(6, 8000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell col_7 = row_col.createCell(7);
		row_col.setHeightInPoints(20);
		col_7.setCellValue("错误数");
		col_7.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(2, 3, 7, 7));
		sheet.setColumnWidth(7, 8000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
	}

	private void createTradeTypeSortContent(HSSFSheet sheet, int startRow, HSSFCellStyle styleContent,
			List<PerformanceView> perfs) {
		for(int i=0; i<perfs.size(); i++){
			int index = 0;
			PerformanceView perfView = perfs.get(i);
			@SuppressWarnings("unchecked")
			List<Map<String, Object>> list = (List<Map<String, Object>>) perfView.get("channel");
			int count = list.size();    // 多少行合并
			Row rowTmp = sheet.createRow(startRow);
			HSSFCellStyle style = createCellStyle(sheet.getWorkbook(), 6);
			for (int j=0; j<4; j++) {
				Cell cellTmp = rowTmp.createCell(j);
				if (j == 0) {
					cellTmp.setCellValue(perfView.get("typeName").toString());
					cellTmp.setCellStyle(style);
					index = sheet.addMergedRegion(new CellRangeAddress(startRow, startRow + count, j, j));
					setRegionStyle(sheet, sheet.getMergedRegion(index), style);
				} else if (j == 1) {
					cellTmp.setCellValue(perfView.get("applicationName").toString());
					cellTmp.setCellStyle(style);
					index = sheet.addMergedRegion(new CellRangeAddress(startRow, startRow + count, j, j));
					setRegionStyle(sheet, sheet.getMergedRegion(index), style);
				} else if (j == 2) {
					cellTmp.setCellValue(perfView.get("serviceName").toString());
					cellTmp.setCellStyle(style);
					index = sheet.addMergedRegion(new CellRangeAddress(startRow, startRow + count, j, j));
					setRegionStyle(sheet, sheet.getMergedRegion(index), style);
				} else if (j == 3) {
					Cell total_title = rowTmp.createCell(j);
					total_title.setCellValue("合计");
					total_title.setCellStyle(style);
					Cell business_throughtput_count = rowTmp.createCell(j+1);
					business_throughtput_count.setCellValue(perfView.get("count").toString());
					business_throughtput_count.setCellStyle(styleContent);
					Cell response_time = rowTmp.createCell(j+2);
					response_time.setCellValue(perfView.get("responseTime").toString());
					response_time.setCellStyle(styleContent);
					Cell success_rate = rowTmp.createCell(j+3);
					success_rate.setCellValue(perfView.get("success_rate").toString());
					success_rate.setCellStyle(styleContent);
					Cell error_count = rowTmp.createCell(j+4);
					error_count.setCellValue(perfView.get("isError").toString());
					error_count.setCellStyle(styleContent);
					
					for(int k=0; k<list.size(); k++){
//						Row row = sheet.createRow(startRow + 1 + k);
						Row row = sheet.getRow(startRow + 1 + k);
						Map<String, Object> map = list.get(k);
						Cell total_title1 = row.createCell(j);
						total_title1.setCellValue(map.get("channelName").toString());
						total_title1.setCellStyle(style);
						Cell business_throughtput_count1 = row.createCell(j+1);
						business_throughtput_count1.setCellValue(map.get("count").toString());
						business_throughtput_count1.setCellStyle(styleContent);
						Cell response_time1 = row.createCell(j+2);
						response_time1.setCellValue(map.get("responseTime").toString());
						response_time1.setCellStyle(styleContent);
						Cell success_rate1 = row.createCell(j+3);
						success_rate1.setCellValue(map.get("success_rate").toString());
						success_rate1.setCellStyle(styleContent);
						Cell error_count1 = row.createCell(j+4);
						error_count1.setCellValue(map.get("isError").toString());
						error_count1.setCellStyle(styleContent);
					}
				}
			}
			startRow += (count + 1);
		}
		
	}

	@Override
	public void downloadTradeSlow(HttpServletRequest request, HttpServletResponse response, int top, long startDate,
			long endDate) {
		try {
			PerformanceResult result = new PerformanceResult();
			if ("NaN".equals(endDate) || "NaN".equals(startDate)) {
				result.setFailMessage("查询时间错误");
				return ;
			}
			@SuppressWarnings("unchecked")
			List<PerformanceView> perfs = (List<PerformanceView>) queryTradeSlowSort(top == 0 ? Integer.MAX_VALUE : top, startDate, endDate).get(Constants.PERFORMANCES);
			String filename = URLEncoder.encode("最慢交易排行报表.xls", "UTF-8");
			OutputStream outPut = response.getOutputStream();
			response.setContentType("application/vnd.ms-excel;charset=UTF-8");
			if("FF".equals(getBrowser(request))){
				response.setContentType("application/vnd.ms-excel;charset=ISO-8859-1");
				filename = new String(filename.getBytes("UTF-8"),"ISO-8859-1");
			}
			response.setHeader("Content-Disposition", "attachment; filename=" + filename + ";filename*=UTF-8''" + filename);

			HSSFWorkbook wb = new HSSFWorkbook();  
			HSSFSheet sheet = wb.createSheet("最慢交易排行报表");

			sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 10));
			Cell cell = sheet.createRow((int) 0).createCell(0);
			cell.setCellValue("最慢交易排行报表");
			cell.setCellStyle(createCellStyle(wb, 1));

			sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, 10));
			Cell cellt = sheet.createRow((int) 1).createCell(0);
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd");
			cellt.setCellValue(sdf.format(new Date(startDate)) + "-" + sdf.format(new Date(endDate)));
			cellt.setCellStyle(createCellStyle(wb, 2));

			createTradeSlowSortHead(sheet, 2, createCellStyle(wb, 3));
			createTradeSlowSortContent(sheet, 4, createCellStyle(wb, 4), perfs);

			wb.write(outPut);
			outPut.close();
		} catch(Exception e){
			log.error("查询性能数据失败：" + e.getMessage());
		}	
		
	}
	
	private void createTradeSlowSortHead(HSSFSheet sheet, int startRow, HSSFCellStyle createCellStyle) {
		int index = 0;
		Row row_col = sheet.createRow(startRow);
		Cell col_0 = row_col.createCell(0);
		row_col.setHeightInPoints(20);
		col_0.setCellValue("交易名称");
		col_0.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(2, 3, 0, 0));
		sheet.setColumnWidth(0, 6000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell col_1 = row_col.createCell(1);
		col_1.setCellValue("业务系统");
		col_1.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(2, 3, 1, 1));
		sheet.setColumnWidth(1, 6000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell col_2 = row_col.createCell(2);
		col_2.setCellValue("服务节点");
		col_2.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(2, 3, 2, 2));
		sheet.setColumnWidth(2, 6000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell col_3 = row_col.createCell(3);
		col_3.setCellValue("渠道");
		col_3.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(2, 3, 3, 3));
		sheet.setColumnWidth(3, 6000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell col_4 = row_col.createCell(4);
		col_4.setCellValue("平均响应时间\r\n(ms)");
		col_4.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(2, 3, 4, 4));
		sheet.setColumnWidth(4, 6000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell col_5 = row_col.createCell(5);
		col_5.setCellValue("最大(ms)");
		col_5.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(2, 3, 5, 5));
		sheet.setColumnWidth(5, 6000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell col_6 = row_col.createCell(6);
		col_6.setCellValue("最小(ms)");
		col_6.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(2, 3, 6, 6));
		sheet.setColumnWidth(6, 6000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell col_7 = row_col.createCell(7);
		row_col.setHeightInPoints(20);
		col_7.setCellValue("总交易量");
		col_7.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(2, 3, 7, 7));
		sheet.setColumnWidth(7, 6000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell col_8 = row_col.createCell(8);
		row_col.setHeightInPoints(20);
		col_8.setCellValue("体验好的次数\r\n<1T");
		col_8.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(2, 3, 8, 8));
		sheet.setColumnWidth(8, 6000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell col_9 = row_col.createCell(9);
		col_9.setCellValue("可容忍的次数\r\n1T-4T");
		col_9.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(2, 3, 9, 9));
		sheet.setColumnWidth(9, 6000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell col_10 = row_col.createCell(10);
		row_col.setHeightInPoints(20);
		col_10.setCellValue("慢交易数\r\n>4T");
		col_10.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(2, 3, 10, 10));
		sheet.setColumnWidth(10, 6000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
	}

	private void createTradeSlowSortContent(HSSFSheet sheet, int startRow, HSSFCellStyle styleContent,
			List<PerformanceView> perfs) {
		for(int i=0; i<perfs.size(); i++){
			int index = 0;
			PerformanceView perfView = perfs.get(i);
			@SuppressWarnings("unchecked")
			List<Map<String, Object>> list = (List<Map<String, Object>>) perfView.get("channel");
			int count = list.size();    // 多少行合并
			Row rowTmp = sheet.createRow(startRow);
			HSSFCellStyle style = createCellStyle(sheet.getWorkbook(), 6);
			for (int j=0; j<4; j++) {
				Cell cellTmp = rowTmp.createCell(j);
				if (j == 0) {
					cellTmp.setCellValue(perfView.get("typeName").toString());
					cellTmp.setCellStyle(style);
					index = sheet.addMergedRegion(new CellRangeAddress(startRow, startRow + count, j, j));
					setRegionStyle(sheet, sheet.getMergedRegion(index), style);
				} else if (j == 1) {
					cellTmp.setCellValue(perfView.get("applicationName").toString());
					cellTmp.setCellStyle(style);
					index = sheet.addMergedRegion(new CellRangeAddress(startRow, startRow + count, j, j));
					setRegionStyle(sheet, sheet.getMergedRegion(index), style);
				} else if (j == 2) {
					cellTmp.setCellValue(perfView.get("serviceName").toString());
					cellTmp.setCellStyle(style);
					index = sheet.addMergedRegion(new CellRangeAddress(startRow, startRow + count, j, j));
					setRegionStyle(sheet, sheet.getMergedRegion(index), style);
				} else if (j == 3) {
					Cell total_title = rowTmp.createCell(j);
					total_title.setCellValue("合计");
					total_title.setCellStyle(style);
					Cell business_throughtput_count = rowTmp.createCell(j+1);
					business_throughtput_count.setCellValue(perfView.get("responseTime").toString());
					business_throughtput_count.setCellStyle(styleContent);
					Cell response_time = rowTmp.createCell(j+2);
					response_time.setCellValue(perfView.get("responseTime_max").toString());
					response_time.setCellStyle(styleContent);
					Cell success_rate = rowTmp.createCell(j+3);
					success_rate.setCellValue(perfView.get("responseTime_min").toString());
					success_rate.setCellStyle(styleContent);
					Cell error_count = rowTmp.createCell(j+4);
					error_count.setCellValue(perfView.get("count").toString());
					error_count.setCellStyle(styleContent);
					Cell satisfied_count = rowTmp.createCell(j+5);
					satisfied_count.setCellValue(perfView.get("apdex_satisfied").toString());
					satisfied_count.setCellStyle(styleContent);
					Cell tolerate_count = rowTmp.createCell(j+6);
					tolerate_count.setCellValue(perfView.get("apdex_tolerate").toString());
					tolerate_count.setCellStyle(styleContent);
					Cell unsatisfied_count = rowTmp.createCell(j+7);
					unsatisfied_count.setCellValue(perfView.get("apdex_unsatisfied").toString());
					unsatisfied_count.setCellStyle(styleContent);
					 
					for(int k=0; k<list.size(); k++){
//						Row row = sheet.createRow(startRow + 1 + k);
						Row row = sheet.getRow(startRow + 1 + k);
						Map<String, Object> map = list.get(k);
						Cell total_title1 = row.createCell(j);
						total_title1.setCellValue(map.get("channelName").toString());
						total_title1.setCellStyle(style);
						Cell business_throughtput_count1 = row.createCell(j+1);
						business_throughtput_count1.setCellValue(map.get("responseTime").toString());
						business_throughtput_count1.setCellStyle(styleContent);
						Cell response_time1 = row.createCell(j+2);
						response_time1.setCellValue(map.get("responseTime_max").toString());
						response_time1.setCellStyle(styleContent);
						Cell success_rate1 = row.createCell(j+3);
						success_rate1.setCellValue(map.get("responseTime_min").toString());
						success_rate1.setCellStyle(styleContent);
						Cell error_count1 = row.createCell(j+4);
						error_count1.setCellValue(map.get("count").toString());
						error_count1.setCellStyle(styleContent);
						Cell satisfied_count1 = row.createCell(j+5);
						satisfied_count1.setCellValue(perfView.get("apdex_satisfied").toString());
						satisfied_count1.setCellStyle(styleContent);
						Cell tolerate_count1 = row.createCell(j+6);
						tolerate_count1.setCellValue(perfView.get("apdex_tolerate").toString());
						tolerate_count1.setCellStyle(styleContent);
						Cell unsatisfied_count1 = row.createCell(j+7);
						unsatisfied_count1.setCellValue(perfView.get("apdex_unsatisfied").toString());
						unsatisfied_count1.setCellStyle(styleContent);
					}
				}
			}
			startRow += (count + 1);
		}
		
	}

	/**
	 * 合并单元格带边框
	 * @param sheet
	 * @param region
	 * @param cs
	 */
	private static void setRegionStyle(HSSFSheet sheet, CellRangeAddress region, HSSFCellStyle cs) {
		for (int i = region.getFirstRow() ; i <= region.getLastRow(); i ++) {
			HSSFRow row = sheet.getRow(i);
			if(row == null){
				row = sheet.createRow(i);
			}
			for (int j = region.getFirstColumn(); j <= region.getLastColumn(); j++) {
				Cell cell = row.getCell(j);
				if(cell == null){
					cell = row.createCell(j);
					cell.setCellValue(" ");
				}
				cell.setCellStyle(cs);
			}
		}
	}

	@Override
	public void downloadTradeFail(HttpServletRequest request, HttpServletResponse response, int top, long startDate,
			long endDate) {
		try {
			PerformanceResult result = new PerformanceResult();
			if ("NaN".equals(endDate) || "NaN".equals(startDate)) {
				result.setFailMessage("查询时间错误");
				return ;
			}
			@SuppressWarnings("unchecked")
			List<PerformanceView> perfs = (List<PerformanceView>) queryTradeFailSort(top == 0 ? Integer.MAX_VALUE : top, startDate, endDate).get(Constants.PERFORMANCES);
			String filename = URLEncoder.encode("异常交易排行报表.xls", "UTF-8");
			OutputStream outPut = response.getOutputStream();
			response.setContentType("application/vnd.ms-excel;charset=UTF-8");
			if("FF".equals(getBrowser(request))){
				response.setContentType("application/vnd.ms-excel;charset=ISO-8859-1");
				filename = new String(filename.getBytes("UTF-8"),"ISO-8859-1");
			}
			response.setHeader("Content-Disposition", "attachment; filename=" + filename + ";filename*=UTF-8''" + filename);

			HSSFWorkbook wb = new HSSFWorkbook();  
			HSSFSheet sheet = wb.createSheet("异常交易排行报表");

			sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 6));
			Cell cell = sheet.createRow((int) 0).createCell(0);
			cell.setCellValue("异常交易排行报表");
			cell.setCellStyle(createCellStyle(wb, 1));

			sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, 6));
			Cell cellt = sheet.createRow((int) 1).createCell(0);
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd");
			cellt.setCellValue(sdf.format(new Date(startDate)) + "-" + sdf.format(new Date(endDate)));
			cellt.setCellStyle(createCellStyle(wb, 2));

			createTradeFailSortHead(sheet, 2, createCellStyle(wb, 3));
			createTradeFailSortContent(sheet, 4, createCellStyle(wb, 4), perfs);

			wb.write(outPut);
			outPut.close();
		} catch(Exception e){
			log.error("查询性能数据失败：" + e.getMessage());
		}	
		
	}

	private void createTradeFailSortContent(HSSFSheet sheet, int startRow, HSSFCellStyle styleContent,
			List<PerformanceView> perfs) {
		int index = 0;
		HSSFCellStyle style = createCellStyle(sheet.getWorkbook(), 6);
		for(int i=0; i<perfs.size(); i++){
			PerformanceView perfView = perfs.get(i);
			@SuppressWarnings("unchecked")
			List<Map<String, Object>> list = (List<Map<String, Object>>) perfView.get("response");
			if (list == null || list.isEmpty()) continue;
			int count = list.size();    // 多少行合并
			Row rowTmp = sheet.createRow(startRow);
			for (int j=0; j<5; j++) {
				Cell cellTmp = rowTmp.createCell(j);
				if (j == 0) {
					cellTmp.setCellValue(perfView.get("typeName").toString());
					cellTmp.setCellStyle(style);
					index = sheet.addMergedRegion(new CellRangeAddress(startRow, startRow + count-1, j, j));
					setRegionStyle(sheet, sheet.getMergedRegion(index), style);
				} else if (j == 1) {
					cellTmp.setCellValue(perfView.get("applicationName").toString());
					cellTmp.setCellStyle(style);
					index = sheet.addMergedRegion(new CellRangeAddress(startRow, startRow + count-1, j, j));
					setRegionStyle(sheet, sheet.getMergedRegion(index), style);
				} else if (j == 2) {
					cellTmp.setCellValue(perfView.get("serviceName").toString());
					cellTmp.setCellStyle(style);
					index = sheet.addMergedRegion(new CellRangeAddress(startRow, startRow + count-1, j, j));
					setRegionStyle(sheet, sheet.getMergedRegion(index), style);
				} else if (j == 3) {
					cellTmp.setCellValue(perfView.get("count").toString());
					cellTmp.setCellStyle(styleContent);
					index = sheet.addMergedRegion(new CellRangeAddress(startRow, startRow + count-1, j, j));
					setRegionStyle(sheet, sheet.getMergedRegion(index), styleContent);
					
				} else if (j == 4) {
//					Map<String, Object> map = list.get(0);
					Cell success_rate1 = rowTmp.createCell(j);
					success_rate1.setCellValue(perfView.get("success_rate").toString());
					success_rate1.setCellStyle(styleContent);
					index = sheet.addMergedRegion(new CellRangeAddress(startRow, startRow + count-1, j, j));
					setRegionStyle(sheet, sheet.getMergedRegion(index), styleContent);
//					Cell total_title1 = rowTmp.createCell(j+1);
//					total_title1.setCellValue(perfView.get("responseCodeString").toString());
//					total_title1.setCellStyle(styleContent);
//					Cell response_time1 = rowTmp.createCell(j+2);
//					response_time1.setCellValue(perfView.get("isError").toString());
//					response_time1.setCellStyle(styleContent);
					if (list != null && list.size() > 0) {
						Cell cells = rowTmp.createCell(j+1);
						cells.setCellValue(list.get(0).get("responseCodeString").toString());
						cells.setCellStyle(styleContent);
						Cell cells2 = rowTmp.createCell(j+2); 
						cells2.setCellValue(list.get(0).get("isError").toString());
						cells2.setCellStyle(styleContent);
						if (list.size() > 1) {
							for(int k=1; k<list.size(); k++){
								Row row = sheet.getRow(startRow + k);
								Map<String, Object> map2 = list.get(k);
//							Cell success_rate2 = row.createCell(j);
//							success_rate2.setCellValue(map2.get("success_rate").toString());
//							success_rate2.setCellStyle(styleContent);
								Cell total_title2 = row.createCell(j+1);
								total_title2.setCellValue(map2.get("responseCodeString").toString());
								total_title2.setCellStyle(styleContent);
								Cell response_time2 = row.createCell(j+2);
								response_time2.setCellValue(map2.get("isError").toString());
								response_time2.setCellStyle(styleContent);
							}
						}
					}
				}
			}
			startRow += count;
		}
		
	}

	private void createTradeFailSortHead(HSSFSheet sheet, int startRow, HSSFCellStyle createCellStyle) {
		int index = 0;
		Row row_col = sheet.createRow(startRow);
		Cell col_0 = row_col.createCell(0);
		row_col.setHeightInPoints(20);
		col_0.setCellValue("交易名称");
		col_0.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(2, 3, 0, 0));
		sheet.setColumnWidth(0, 8000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell col_1 = row_col.createCell(1);
		col_1.setCellValue("业务系统");
		col_1.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(2, 3, 1, 1));
		sheet.setColumnWidth(1, 8000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell col_2 = row_col.createCell(2);
		col_2.setCellValue("服务节点");
		col_2.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(2, 3, 2, 2));
		sheet.setColumnWidth(2, 8000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell col_3 = row_col.createCell(3);
		col_3.setCellValue("总交易量");
		col_3.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(2, 3, 3, 3));
		sheet.setColumnWidth(3, 8000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell col_4 = row_col.createCell(4);
		col_4.setCellValue("成功率%");
		col_4.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(2, 3, 4, 4));
		sheet.setColumnWidth(4, 8000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell col_5 = row_col.createCell(5);
		col_5.setCellValue("返回码");
		col_5.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(2, 3, 5, 5));
		sheet.setColumnWidth(5, 8000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell col_6 = row_col.createCell(6);
		col_6.setCellValue("错误数");
		col_6.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(2, 3, 6, 6));
		sheet.setColumnWidth(6, 8000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
	}

	@Override
	public PerformanceResult querySystemPerformance(long startDate, long endDate) {
		long startTime1 = System.currentTimeMillis();
		PerformanceResult result = new PerformanceResult();
		if ("NaN".equals(startDate) || "NaN".equals(endDate)) {
			result.setFailMessage("时间参数是NAN");
			return result;
		}
		if (endDate == 0)
			endDate = System.currentTimeMillis();
		if (startDate == 0)
			startDate = endDate - 60 * 60 * 1000;
		
		List<PerformanceView> appPerfList = new ArrayList<PerformanceView>();
		long startTime2 = System.currentTimeMillis();
		List<PerformanceView> appPerformanceList = perfLogic.queryAppTermsPerfs(new Date(startDate), new Date(endDate));
		log.error("系统性能报表ES查询用时：" + (System.currentTimeMillis() - startTime2));
		for (PerformanceView perf : appPerformanceList) {
			ApplicationSystem application = appLogic.getApplicationById(perf.getApplicationId());
			if (application == null) continue;
			perf.put("applicationName", application.getName());
			perf.put("system/throughput/total_minute", perf.get("system/throughput/total") == null ? "-" : new DecimalFormat("0.00").format(Double.parseDouble(perf.get("system/throughput/total").toString()) / ((endDate - startDate) / 60 / 1000)));
			perf.put("system/throughput/total", perf.get("system/throughput/total") == null ? "-" : (long)Double.parseDouble(perf.get("system/throughput/total").toString()));
			perf.put("system/response_time/avg", (perf.get("system/response_time/total") == null || perf.get("system/throughput/total") == null || Double.parseDouble(perf.get("system/throughput/total").toString()) == 0) ? "-" : new DecimalFormat("0.00").format(Double.parseDouble(perf.get("system/response_time/total").toString()) / Double.parseDouble(perf.get("system/throughput/total").toString()) / 1000));
			perf.put("system/success/rate", (perf.get("system/throughput/total") == null || perf.get("system/error/count") == null || Double.parseDouble(perf.get("system/throughput/total").toString()) == 0) ? "-" : new DecimalFormat("0.00").format((Double.parseDouble(perf.get("system/throughput/total").toString()) - Double.parseDouble(perf.get("system/error/count").toString())) / (Double.parseDouble(perf.get("system/throughput/total").toString())) * 100));
			perf.put("system/error/count_minute", perf.get("system/error/count") == null ? "-" : new DecimalFormat("0.00").format(Double.parseDouble(perf.get("system/error/count").toString()) / ((endDate - startDate) / 60 / 1000)));
			perf.put("system/error/count", perf.get("system/error/count") == null ? "-" : (long)Double.parseDouble(perf.get("system/error/count").toString()));
			
			perf.put("business/throughput/total_minute", perf.get("business/throughput/total") == null ? "-" : new DecimalFormat("0.00").format(Double.parseDouble(perf.get("business/throughput/total").toString()) / ((endDate - startDate) / 60 / 1000)));
			perf.put("business/throughput/total", perf.get("business/throughput/total") == null ? "-" : (long)Double.parseDouble(perf.get("business/throughput/total").toString()));
			perf.put("business/response_time/avg", (perf.get("business/response_time/total") == null || perf.get("business/throughput/total") == null || Double.parseDouble(perf.get("business/throughput/total").toString()) == 0) ? "-" : new DecimalFormat("0.00").format(Double.parseDouble(perf.get("business/response_time/total").toString()) / Double.parseDouble(perf.get("business/throughput/total").toString()) / 1000));
			perf.put("business/success/rate", (perf.get("business/throughput/total") == null || perf.get("business/error/count") == null || Double.parseDouble(perf.get("business/throughput/total").toString()) == 0) ? "-" : new DecimalFormat("0.00").format((Double.parseDouble(perf.get("business/throughput/total").toString()) - Double.parseDouble(perf.get("business/error/count").toString())) / (Double.parseDouble(perf.get("business/throughput/total").toString())) * 100));
			perf.put("business/error/count_minute", perf.get("business/error/count") == null ? "-" : new DecimalFormat("0.00").format(Double.parseDouble(perf.get("business/error/count").toString()) / ((endDate - startDate) / 60 / 1000)));
			perf.put("business/error/count", perf.get("business/error/count") == null ? "-" : (long)Double.parseDouble(perf.get("business/error/count").toString()));
			appPerfList.add(perf);
		}
		
		result.setPerformances(tradeSort(appPerfList, "system/throughput/total", "desc", appPerfList.size()));
		log.error("系统性能报表总用时：" + (System.currentTimeMillis() - startTime1));
		return result;
	}

	@Override
	public void downloadSystemPerformance(HttpServletRequest request, HttpServletResponse response,
			long startDate, long endDate) {
		try {
			PerformanceResult result = new PerformanceResult();
			if ("NaN".equals(endDate) || "NaN".equals(startDate)) {
				result.setFailMessage("查询时间错误");
				return ;
			}
			@SuppressWarnings("unchecked")
			List<PerformanceView> perfs = (List<PerformanceView>) querySystemPerformance(startDate, endDate).get(Constants.PERFORMANCES);
			String filename = URLEncoder.encode("系统性能报表.xls", "UTF-8");
			OutputStream outPut = response.getOutputStream();
			response.setContentType("application/vnd.ms-excel;charset=UTF-8");
			if("FF".equals(getBrowser(request))){
				response.setContentType("application/vnd.ms-excel;charset=ISO-8859-1");
				filename = new String(filename.getBytes("UTF-8"),"ISO-8859-1");
			}
			response.setHeader("Content-Disposition", "attachment; filename=" + filename + ";filename*=UTF-8''" + filename);

			HSSFWorkbook wb = new HSSFWorkbook();  
			HSSFSheet sheet = wb.createSheet("系统性能报表");

			sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 12));
			Cell cell = sheet.createRow((int) 0).createCell(0);
			cell.setCellValue("系统性能报表");
			cell.setCellStyle(createCellStyle(wb, 1));

			sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, 12));
			Cell cellt = sheet.createRow((int) 1).createCell(0);
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd");
			cellt.setCellValue(sdf.format(new Date(startDate)) + "-" + sdf.format(new Date(endDate)));
			cellt.setCellStyle(createCellStyle(wb, 2));

			createAppPerfHead(sheet, 2, createCellStyle(wb, 3));
			createAppPerfContent(sheet, 4, createCellStyle(wb, 4), perfs);

			wb.write(outPut);
			outPut.close();
		} catch(Exception e){
			log.error("查询性能数据失败：" + e.getMessage());
		}	
		
	}

	private void createAppPerfHead(HSSFSheet sheet, int startRow, HSSFCellStyle styleContent) {
		int index = 0;
		Row row_col = sheet.createRow(startRow);
		Cell col_0 = row_col.createCell(0);
		row_col.setHeightInPoints(20);
		col_0.setCellValue("系统名称");
		col_0.setCellStyle(styleContent);
		index = sheet.addMergedRegion(new CellRangeAddress(2, 3, 0, 0));
		sheet.setColumnWidth(0, 8000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), styleContent);
		
		Cell col_1 = row_col.createCell(1);
		col_1.setCellValue("系统级");
		col_1.setCellStyle(styleContent);
		index = sheet.addMergedRegion(new CellRangeAddress(2, 2, 1, 6));
		sheet.setColumnWidth(1, 8000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), styleContent);
		
		Cell col_11 = row_col.createCell(7);
		col_11.setCellValue("交易级");
		col_11.setCellStyle(styleContent);
		index = sheet.addMergedRegion(new CellRangeAddress(2, 2, 7, 12));
		sheet.setColumnWidth(2, 8000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), styleContent);
		
//		Row row_col3 = sheet.createRow(3);
		Row row_col3 = sheet.getRow(3);
		row_col3.setHeightInPoints(48);
		Cell col_2 = row_col3.createCell(1);
		col_2.setCellValue("总吞吐量");
		col_2.setCellStyle(styleContent);
		index = sheet.addMergedRegion(new CellRangeAddress(3, 3, 1, 1));
		sheet.setColumnWidth(3, 4000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), styleContent);
		
		Cell col_3 = row_col3.createCell(2);
		col_3.setCellValue("吞吐量/分钟");
		col_3.setCellStyle(styleContent);
		index = sheet.addMergedRegion(new CellRangeAddress(3, 3, 2, 2));
		sheet.setColumnWidth(4, 4000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), styleContent);
		
		Cell col_4 = row_col3.createCell(3);
		col_4.setCellValue("平均响应时间ms");
		col_4.setCellStyle(styleContent);
		index = sheet.addMergedRegion(new CellRangeAddress(3, 3, 3, 3));
		sheet.setColumnWidth(5, 4000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), styleContent);
		
		Cell col_5 = row_col3.createCell(4);
		col_5.setCellValue("成功率%");
		col_5.setCellStyle(styleContent);
		index = sheet.addMergedRegion(new CellRangeAddress(3, 3, 4, 4));
		sheet.setColumnWidth(6, 4000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), styleContent);
		
		Cell col_6 = row_col3.createCell(5);
		col_6.setCellValue("错误数");
		col_6.setCellStyle(styleContent);
		index = sheet.addMergedRegion(new CellRangeAddress(3, 3, 5, 5));
		sheet.setColumnWidth(7, 4000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), styleContent);
		
		Cell col_7 = row_col3.createCell(6);
		col_7.setCellValue("错误数/分钟");
		col_7.setCellStyle(styleContent);
		index = sheet.addMergedRegion(new CellRangeAddress(3, 3, 6, 6));
		sheet.setColumnWidth(8, 4000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), styleContent);
		
		Cell col_8 = row_col3.createCell(7);
		col_8.setCellValue("总交易量");
		col_8.setCellStyle(styleContent);
		index = sheet.addMergedRegion(new CellRangeAddress(3, 3, 7, 7));
		sheet.setColumnWidth(9, 4000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), styleContent);
		
		Cell col_9 = row_col3.createCell(8);
		col_9.setCellValue("交易量/分钟");
		col_9.setCellStyle(styleContent);
		index = sheet.addMergedRegion(new CellRangeAddress(3, 3, 8, 8));
		sheet.setColumnWidth(10, 4000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), styleContent);
		
		Cell col_10 = row_col3.createCell(9);
		col_10.setCellValue("平均响应时间ms");
		col_10.setCellStyle(styleContent);
		index = sheet.addMergedRegion(new CellRangeAddress(3, 3, 9, 9));
		sheet.setColumnWidth(11, 4000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), styleContent);
		
		Cell col_12 = row_col3.createCell(10);
		col_12.setCellValue("成功率%");
		col_12.setCellStyle(styleContent);
		index = sheet.addMergedRegion(new CellRangeAddress(3, 3, 10, 10));
		sheet.setColumnWidth(12, 4000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), styleContent);
		
		Cell col_13 = row_col3.createCell(11);
		col_13.setCellValue("错误数");
		col_13.setCellStyle(styleContent);
		index = sheet.addMergedRegion(new CellRangeAddress(3, 3, 11, 11));
		sheet.setColumnWidth(13, 4000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), styleContent);
		
		Cell col_14 = row_col3.createCell(12);
		col_14.setCellValue("错误数/分钟");
		col_14.setCellStyle(styleContent);
		index = sheet.addMergedRegion(new CellRangeAddress(3, 3, 12, 12));
		sheet.setColumnWidth(14, 4000);
		setRegionStyle(sheet, sheet.getMergedRegion(index), styleContent);
		
	}

	private void createAppPerfContent(HSSFSheet sheet, int startRow, HSSFCellStyle styleContent,
			List<PerformanceView> perfs) {
		for (int i=0; i<perfs.size(); i++) {
			PerformanceView pv = perfs.get(i);
			Row rowTmp = sheet.createRow(startRow + i);
			for (int j=0; j<13; j++) {
				Cell cellTmp = rowTmp.createCell(j);
				if (j == 0) {
					cellTmp.setCellValue(pv.get("applicationName").toString());
					cellTmp.setCellStyle(createCellStyle(sheet.getWorkbook(), 6));
				} else if (j == 1) {
					cellTmp.setCellValue(pv.get("system/throughput/total").toString());
					cellTmp.setCellStyle(styleContent);
				} else if (j == 2) {
					cellTmp.setCellValue(pv.get("system/throughput/total_minute").toString());
					cellTmp.setCellStyle(styleContent);
				} else if (j == 3) {
					cellTmp.setCellValue(pv.get("system/response_time/avg").toString());
					cellTmp.setCellStyle(styleContent);
				} else if (j == 4) {
					cellTmp.setCellValue(pv.get("system/success/rate").toString());
					cellTmp.setCellStyle(styleContent);
				} else if (j == 5) {
					cellTmp.setCellValue(pv.get("system/error/count").toString());
					cellTmp.setCellStyle(styleContent);
				} else if (j == 6) {
					cellTmp.setCellValue(pv.get("system/error/count_minute").toString());
					cellTmp.setCellStyle(styleContent);
				} else if (j == 7) {
					cellTmp.setCellValue(pv.get("business/throughput/total").toString());
					cellTmp.setCellStyle(styleContent);
				} else if (j == 8) {
					cellTmp.setCellValue(pv.get("business/throughput/total_minute").toString());
					cellTmp.setCellStyle(styleContent);
				} else if (j == 9) {
					cellTmp.setCellValue(pv.get("business/response_time/avg").toString());
					cellTmp.setCellStyle(styleContent);
				} else if (j == 10) {
					cellTmp.setCellValue(pv.get("business/success/rate").toString());
					cellTmp.setCellStyle(styleContent);
				} else if (j == 11) {
					cellTmp.setCellValue(pv.get("business/error/count").toString());
					cellTmp.setCellStyle(styleContent);
				} else if (j == 12) {
					cellTmp.setCellValue(pv.get("business/error/count_minute").toString());
					cellTmp.setCellStyle(styleContent);
				}
			}
		}
		
	}

	@Override
	public PerformanceResult queryYjhTradeIndicator(long startDate, long endDate) {
		PerformanceResult result = new PerformanceResult();
		List<PerformanceView> resultList = new ArrayList<PerformanceView>();
		if ("NaN".equals(startDate) || "NaN".equals(endDate)) {
			result.setFailMessage("时间参数是NAN");
			return result;
		}
		if (endDate == 0)
			endDate = System.currentTimeMillis();
		if (startDate == 0)
			startDate = endDate - 60 * 60 * 1000;
		
		long history_startDate = startDate;
		long history_endDate = endDate;
		if ((endDate - startDate) <= 24 * 60 * 60 * 1000) {
			history_startDate = startDate - 24 * 60 * 60 * 1000;
			history_endDate = endDate - 24 * 60 * 60 * 1000;
		} else if ((endDate - startDate) <= 7 * 24 * 60 * 60 * 1000) {
			history_startDate = startDate - 7 * 24 * 60 * 60 * 1000;
			history_endDate = endDate - 7 * 24 * 60 * 60 * 1000;
		} else {
			Calendar sd = Calendar.getInstance();
			sd.setTime(new Date(startDate));
			sd.set(Calendar.HOUR_OF_DAY, 0);
			sd.set(Calendar.MINUTE, 0);
			sd.set(Calendar.SECOND, 0);
			sd.set(Calendar.MILLISECOND, 0);
			sd.add(Calendar.MONTH, -1);
			
			Calendar ed = Calendar.getInstance();
			ed.setTime(new Date(endDate));
			ed.set(Calendar.HOUR_OF_DAY, 0);
			ed.set(Calendar.MINUTE, 0);
			ed.set(Calendar.SECOND, 0);
			ed.set(Calendar.MILLISECOND, 0);
			ed.add(Calendar.MONTH, -1);
			
			history_startDate = sd.getTime().getTime();
			history_endDate = ed.getTime().getTime();
		}
		
		List<PerformanceView> yjhTradeLevel1Perfs = tradePerformanceLogic.getTradeMergeByStability("stability_level1", new Date(startDate), new Date(endDate));
		List<PerformanceView> yjhTradeLevel2Perfs = tradePerformanceLogic.getTradeMergeByStability("stability_level2", new Date(startDate), new Date(endDate));
		List<PerformanceView> yjhTradeScaleLevelPerfs = tradePerformanceLogic.getTradeMergeByStability("scale_level1", new Date(startDate), new Date(endDate));
		List<PerformanceView> yjhTradeScaleLevelHitoryPerfs = tradePerformanceLogic.getTradeMergeByStability("scale_level1", new Date(history_startDate), new Date(history_endDate));
		
		PerformanceView perf = new PerformanceView();
		List<PerformanceView> yjhTradeLevel = new ArrayList<PerformanceView>();
		for (PerformanceView level1 : yjhTradeLevel1Perfs) {
			if (Arrays.asList(YJH_STABILITY_LEVEL11).contains(level1.get("stability_level1"))) {
				yjhTradeLevel.add(level1);
			}
		}
		for (PerformanceView level1 : yjhTradeLevel) {
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("count", level1.get("count"));
			map.put("success_count", level1.get("count"));
			map.put("success_rate", new DecimalFormat("0.00").format((Double.parseDouble(level1.get("count").toString()) - Double.parseDouble(level1.get("isError").toString())) / Double.parseDouble(level1.get("count").toString()) * 100));
			perf.put(level1.get("stability_level1").toString(), map);
		}
		for (PerformanceView level2 : yjhTradeLevel2Perfs) {
			List<String> level11 = Arrays.asList(YJH_STABILITY_LEVEL11);
			if (level11.contains(level2.get("stability_level1"))) {
				continue;
			}
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("count", level2.get("count"));
			map.put("success_count", Double.parseDouble(level2.get("count").toString()) - Double.parseDouble(level2.get("isError").toString()));
			map.put("success_rate", new DecimalFormat("0.00").format((Double.parseDouble(level2.get("count").toString()) - Double.parseDouble(level2.get("isError").toString())) / Double.parseDouble(level2.get("count").toString()) * 100));
			perf.put(level2.get("stability_level1") + "_" + level2.get("stability_level2"), map);
		}
		
		for (PerformanceView scalePerf : yjhTradeScaleLevelPerfs) {
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("this_count", scalePerf.get("count"));
			for (PerformanceView hisScalePerf : yjhTradeScaleLevelHitoryPerfs) {
				if (scalePerf.get("scale_level1").equals(hisScalePerf.get("scale_level1"))) {
					map.put("history_count", hisScalePerf.get("count"));
					map.put("count_rate", (scalePerf.get("count") == null || hisScalePerf.get("count") == null || Double.parseDouble(hisScalePerf.get("count").toString()) == 0) ? "-" : new DecimalFormat("0.00").format((Double.parseDouble(scalePerf.get("count").toString()) - Double.parseDouble(hisScalePerf.get("count").toString())) / Double.parseDouble(hisScalePerf.get("count").toString()) * 100));
				}
			}
			perf.put(scalePerf.get("scale_level1") + "交易变化率", map);
		}
		resultList.add(perf);
		
		result.setPerformances(resultList);
		return result;
	}

	@Override
	public void downloadYjhTradeIndicator(HttpServletRequest request, HttpServletResponse response,
			long startDate, long endDate) {
		try {
			PerformanceResult result = new PerformanceResult();
			if ("NaN".equals(endDate) || "NaN".equals(startDate)) {
				result.setFailMessage("查询时间错误");
				return ;
			}
			@SuppressWarnings("unchecked")
			List<PerformanceView> perfs = (List<PerformanceView>) queryYjhTradeIndicator(startDate, endDate).get(Constants.PERFORMANCES);
			String filename = URLEncoder.encode("银监会动态监测指标日报.xls", "UTF-8");
			OutputStream outPut = response.getOutputStream();
			response.setContentType("application/vnd.ms-excel;charset=UTF-8");
			if("FF".equals(getBrowser(request))){
				response.setContentType("application/vnd.ms-excel;charset=ISO-8859-1");
				filename = new String(filename.getBytes("UTF-8"),"ISO-8859-1");
			}
			response.setHeader("Content-Disposition", "attachment; filename=" + filename + ";filename*=UTF-8''" + filename);

			HSSFWorkbook wb = new HSSFWorkbook();  
			HSSFSheet sheet = wb.createSheet("银监会动态监测指标日报");

			sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 5));
			Cell cell = sheet.createRow((int) 0).createCell(0);
			cell.setCellValue("银监会动态监测指标日报");
			cell.setCellStyle(createCellStyle(wb, 1));

			sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, 5));
			Cell cellt = sheet.createRow((int) 1).createCell(0);
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd");
			cellt.setCellValue(sdf.format(new Date(startDate)) + "-" + sdf.format(new Date(endDate)));
			cellt.setCellStyle(createCellStyle(wb, 2));

			createYjhTradeIndicatorHead(sheet, 2, createCellStyle(wb, 3));
			createYjhTradeIndicatorContent(sheet, createCellStyle(wb, 4), createCellStyle(wb, 5), perfs);
			createYjhTradeIndicatorContentElse(sheet, createCellStyle(wb, 4), perfs);

			wb.write(outPut);
			outPut.close();
		} catch(Exception e){
			log.error("查询性能数据失败：" + e.getMessage());
		}	
		
	}

	private void createYjhTradeIndicatorContentElse(HSSFSheet sheet, HSSFCellStyle createCellStyle, List<PerformanceView> perfs) {
		if (perfs.isEmpty()) {
			return;
		}
		PerformanceView perf = perfs.get(0);
		int flag = 4;
		HSSFCellStyle style = createCellStyle(sheet.getWorkbook(), 6);
		for (int i=0; i<RESULT_KEY.length; i++) {
			@SuppressWarnings("unchecked")
			Map<String, Object> map = (Map<String, Object>) perf.get(RESULT_KEY[i]);
//			if (map == null || map.isEmpty()) {
//				flag = flag + 3;
//				continue;
//			}
			sheet.addMergedRegion(new CellRangeAddress(flag, flag, 4, 4));
			Row row3 = sheet.getRow(flag);
			row3.setHeightInPoints(25);
			Cell cell2 = row3.createCell(4);
			cell2.setCellValue("系统交易总量");
			cell2.setCellStyle(style);
			
			Cell cell3 = row3.createCell(5);
			cell3.setCellValue(map == null || map.get("count") == null ? "-" : Double.valueOf(map.get("count").toString()).intValue()+"" );
			cell3.setCellStyle(createCellStyle);
			sheet.addMergedRegion(new CellRangeAddress(flag, flag, 5, 5));
			
			sheet.addMergedRegion(new CellRangeAddress(flag + 1, flag + 1, 4, 4));
			Row row5 = sheet.getRow(flag + 1);
			row5.setHeightInPoints(25);
			Cell cell4 = row5.createCell(4);
			cell4.setCellValue("系统交易成功率");
			cell4.setCellStyle(style);
			
			Cell cell5 = row5.createCell(5);
			cell5.setCellValue(map == null || map.get("success_rate") == null ? "-" : map.get("success_rate").toString()+"%");
			cell5.setCellStyle(createCellStyle);
			sheet.addMergedRegion(new CellRangeAddress(flag + 1, flag + 1, 5, 5));
			
			flag = flag + 3;
		}
		
		flag = flag + 1;
		for (int i=0; i<YJH_SCALE_LEVEL1.length; i++) {
			@SuppressWarnings("unchecked")
			Map<String, Object> map = (Map<String, Object>) perf.get(YJH_SCALE_LEVEL1[i] + "交易变化率");
//			if (map == null || map.isEmpty()) {
//				flag = flag + 3;
//				continue;
//			}
			sheet.addMergedRegion(new CellRangeAddress(flag, flag, 4, 4));
			Row row54 = sheet.getRow(flag);
			row54.setHeightInPoints(25);
			Cell cell2 = row54.createCell(4);
			cell2.setCellValue("上期交易量");
			cell2.setCellStyle(style);
			
			Cell cell53 = row54.createCell(5);
			cell53.setCellValue(map == null || map.get("history_count") == null ? "-" : Double.valueOf(map.get("history_count").toString()).intValue()+"");
			cell53.setCellStyle(createCellStyle);
			sheet.addMergedRegion(new CellRangeAddress(flag, flag, 5, 5));
			
			sheet.addMergedRegion(new CellRangeAddress(flag + 1, flag + 1, 4, 4));
			Row row55 = sheet.getRow(flag + 1);
			row55.setHeightInPoints(25);
			Cell cell4 = row55.createCell(4);
			cell4.setCellValue("变化率");
			cell4.setCellStyle(style);
			
			Cell cell54 = row55.createCell(5);
			cell54.setCellValue(map == null || map.get("count_rate") == null ? "-" : map.get("count_rate").toString()+"%");
			cell54.setCellStyle(createCellStyle);
			sheet.addMergedRegion(new CellRangeAddress(flag + 1, flag + 1, 5, 5));
			
			flag = flag + 3;
		}
		
	}

	@SuppressWarnings("unchecked")
	private void createYjhTradeIndicatorContent(HSSFSheet sheet, HSSFCellStyle createCotentCellStyle, HSSFCellStyle createCellStyle, List<PerformanceView> perfs) {
		PerformanceView perf = perfs.isEmpty() ? new PerformanceView() : perfs.get(0);
		HSSFCellStyle style = createCellStyle(sheet.getWorkbook(), 6);
		int index = 0;
		sheet.setColumnWidth(5, 18*256);
		Row row_type = sheet.createRow(3);
		row_type.setHeightInPoints(25);
		Cell cell_type = row_type.createCell(0);
		cell_type.setCellValue("稳定性");
		cell_type.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(3, 50, 0, 0));
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell cell_typeName = row_type.createCell(1);
		cell_typeName.setCellValue("系统交易成功率");
		cell_typeName.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(3, 50, 1, 1));
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell cell_type1 = row_type.createCell(2);
		cell_type1.setCellValue("核心业务系统交易成功率");
		cell_type1.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(3, 8, 2, 2));
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell cell_type2 = row_type.createCell(3);
		cell_type2.setCellValue("资金变动类交易成功率");
		cell_type2.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(3, 5, 3, 3));
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell cell1a = row_type.createCell(4);
		cell1a.setCellValue("系统成功交易量");
		cell1a.setCellStyle(style);
		sheet.addMergedRegion(new CellRangeAddress(3, 3, 4, 4));
		
		Cell cell1 = row_type.createCell(5);
		cell1.setCellValue((perf.get("核心业务系统_资金变动类") == null
				|| ((Map<String, Object>) perf.get("核心业务系统_资金变动类")).get("success_count") == null) ? "-"
						: Double.valueOf(((Map<String, Object>) perf.get("核心业务系统_资金变动类")).get("success_count").toString()).intValue()+"");
		cell1.setCellStyle(createCotentCellStyle);
		sheet.addMergedRegion(new CellRangeAddress(3, 3, 5, 5));
		
		Row row3 = sheet.getRow(6);
		row3.setHeightInPoints(25);
		Cell cell_type3 = row3.createCell(3);
		cell_type3.setCellValue("非资金变动类交易成功率");
		cell_type3.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(6, 8, 3, 3));
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell cell4a = row3.createCell(4);
		cell4a.setCellValue("系统成功交易量");
		cell4a.setCellStyle(style);
		sheet.addMergedRegion(new CellRangeAddress(6, 6, 4, 4));
		
		Cell cell4 = row3.createCell(5);
		cell4.setCellValue((perf.get("核心业务系统_非资金变动类") == null
				|| ((Map<String, Object>) perf.get("核心业务系统_非资金变动类")).get("success_count") == null) ? "-"
						: Double.valueOf(((Map<String, Object>) perf.get("核心业务系统_非资金变动类")).get("success_count").toString()).intValue()+"" );
		cell4.setCellStyle(createCotentCellStyle);
		sheet.addMergedRegion(new CellRangeAddress(6, 6, 5, 5));
		
		Row row4 = sheet.getRow(9);
		row4.setHeightInPoints(25);
		Cell cell_type7 = row4.createCell(2);
		cell_type7.setCellValue("综合前置系统交易成功率");
		cell_type7.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(9, 26, 2, 2));
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell cell7a = row4.createCell(4);
		cell7a.setCellValue("系统成功交易量");
		cell7a.setCellStyle(style);
		sheet.addMergedRegion(new CellRangeAddress(9, 9, 4, 4));
		
		Cell cell7 = row4.createCell(5);
		cell7.setCellValue((perf.get("综合前置系统_大小额支付前置系统") == null
				|| ((Map<String, Object>) perf.get("综合前置系统_大小额支付前置系统")).get("success_count") == null) ? "-"
						: Double.valueOf(((Map<String, Object>) perf.get("综合前置系统_大小额支付前置系统")).get("success_count").toString()).intValue()+"" );
		cell7.setCellStyle(createCotentCellStyle);
		sheet.addMergedRegion(new CellRangeAddress(9, 9, 5, 5));
		
		Cell cell_type8 = row4.createCell(3);
		cell_type8.setCellValue("大小额支付前置系统交易成功率");
		cell_type8.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(9, 11, 3, 3));
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Row row6 = sheet.getRow(12);
		row6.setHeightInPoints(25);
		Cell cell_type9 = row6.createCell(3);
		cell_type9.setCellValue("ATM前置系统交易成功率");
		cell_type9.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(12, 14, 3, 3));
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell cell10a = row6.createCell(4);
		cell10a.setCellValue("系统成功交易量");
		cell10a.setCellStyle(style);
		sheet.addMergedRegion(new CellRangeAddress(12, 12, 4, 4));
		
		Cell cell10 = row6.createCell(5);
		cell10.setCellValue((perf.get("综合前置系统_ATM前置系统") == null
				|| ((Map<String, Object>) perf.get("综合前置系统_ATM前置系统")).get("success_count") == null) ? "-"
						: Double.valueOf(((Map<String, Object>) perf.get("综合前置系统_ATM前置系统")).get("success_count").toString()).intValue()+"" );
		cell10.setCellStyle(createCotentCellStyle);
		sheet.addMergedRegion(new CellRangeAddress(12, 12, 5, 5));
		
		Row row7 = sheet.getRow(15);
		row7.setHeightInPoints(25);
		Cell cell_type10 = row7.createCell(3);
		cell_type10.setCellValue("cd");
		cell_type10.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(15, 17, 3, 3));
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell cell16a = row7.createCell(4);
		cell16a.setCellValue("系统成功交易量");
		cell16a.setCellStyle(style);
		sheet.addMergedRegion(new CellRangeAddress(15, 15, 4, 4));
		
		Cell cell16 = row7.createCell(5);
		cell16.setCellValue((perf.get("综合前置系统_银联前置系统") == null
				|| ((Map<String, Object>) perf.get("综合前置系统_银联前置系统")).get("success_count") == null) ? "-"
						: Double.valueOf(((Map<String, Object>) perf.get("综合前置系统_银联前置系统")).get("success_count").toString()).intValue() + "");
		cell16.setCellStyle(createCotentCellStyle);
		sheet.addMergedRegion(new CellRangeAddress(15, 15, 5, 5));
		
		Row row8 = sheet.getRow(18);
		row8.setHeightInPoints(25);
		Cell cell_type11 = row8.createCell(3);
		cell_type11.setCellValue("超级网银前置系统交易成功率");
		cell_type11.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(18, 20, 3, 3));
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell cell19a = row8.createCell(4);
		cell19a.setCellValue("系统成功交易量");
		cell19a.setCellStyle(style);
		sheet.addMergedRegion(new CellRangeAddress(18, 18, 4, 4));
		
		Cell cell19 = row8.createCell(5);
		cell19.setCellValue((perf.get("综合前置系统_超级网银前置系统") == null
				|| ((Map<String, Object>) perf.get("综合前置系统_超级网银前置系统")).get("success_count") == null) ? "-"
						: Double.valueOf(((Map<String, Object>) perf.get("综合前置系统_超级网银前置系统")).get("success_count").toString()).intValue() + "");
		cell19.setCellStyle(createCotentCellStyle);
		sheet.addMergedRegion(new CellRangeAddress(18, 18, 5, 5));
		
		Row row9 = sheet.getRow(21);
		row9.setHeightInPoints(25);
		Cell cell_type12 = row9.createCell(3);
		cell_type12.setCellValue("POS渠道交易成功率");
		cell_type12.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(21, 23, 3, 3));
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell cell22a = row9.createCell(4);
		cell22a.setCellValue("系统成功交易量");
		cell22a.setCellStyle(style);
		sheet.addMergedRegion(new CellRangeAddress(21, 21, 4, 4));
		
		Cell cell22 = row9.createCell(5);
		cell22.setCellValue((perf.get("综合前置系统_POS渠道") == null
				|| ((Map<String, Object>) perf.get("综合前置系统_POS渠道")).get("success_count") == null) ? "-"
						: Double.valueOf(((Map<String, Object>) perf.get("综合前置系统_POS渠道")).get("success_count").toString()).intValue() + "");
		cell22.setCellStyle(createCotentCellStyle);
		sheet.addMergedRegion(new CellRangeAddress(21, 21, 5, 5));
		
		Row row10 = sheet.getRow(24);
		row10.setHeightInPoints(25);
		Cell cell_type13 = row10.createCell(3);
		cell_type13.setCellValue("第三方存管前置系统交易成功率");
		cell_type13.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(24, 26, 3, 3));
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell cell25a = row10.createCell(4);
		cell25a.setCellValue("系统成功交易量");
		cell25a.setCellStyle(style);
		sheet.addMergedRegion(new CellRangeAddress(24, 24, 4, 4));
		
		Cell cell25 = row10.createCell(5);
		cell25.setCellValue((perf.get("综合前置系统_第三方存管前置系统") == null
				|| ((Map<String, Object>) perf.get("综合前置系统_第三方存管前置系统")).get("success_count") == null) ? "-"
						: Double.valueOf(((Map<String, Object>) perf.get("综合前置系统_第三方存管前置系统")).get("success_count").toString()).intValue() + "");
		cell25.setCellStyle(createCotentCellStyle);
		sheet.addMergedRegion(new CellRangeAddress(24, 24, 5, 5));
		
		Row row5 = sheet.getRow(27);
		row5.setHeightInPoints(25);
		Cell cell_type14 = row5.createCell(2);
		cell_type14.setCellValue("信用卡系统交易成功率");
		cell_type14.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(27, 38, 2, 2));
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell cell28a = row5.createCell(4);
		cell28a.setCellValue("系统成功交易量");
		cell28a.setCellStyle(style);
		sheet.addMergedRegion(new CellRangeAddress(27, 27, 4, 4));
		
		Cell cell28 = row5.createCell(5);
		cell28.setCellValue((perf.get("信用卡系统_电话银行渠道") == null
				|| ((Map<String, Object>) perf.get("信用卡系统_电话银行渠道")).get("success_count") == null) ? "-"
						: Double.valueOf(((Map<String, Object>) perf.get("信用卡系统_电话银行渠道")).get("success_count").toString()).intValue() + "");
		cell28.setCellStyle(createCotentCellStyle);
		sheet.addMergedRegion(new CellRangeAddress(27, 27, 5, 5));
		
		Cell cell_type15 = row5.createCell(3);
		cell_type15.setCellValue("电话银行渠道交易成功率");
		cell_type15.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(27, 29, 3, 3));
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Row row30 = sheet.getRow(30);
		row30.setHeightInPoints(25);
		Cell cell_type16 = row30.createCell(3);
		cell_type16.setCellValue("手机银行渠道交易成功率");
		cell_type16.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(30, 32, 3, 3));
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell cell31a = row30.createCell(4);
		cell31a.setCellValue("系统成功交易量");
		cell31a.setCellStyle(style);
		sheet.addMergedRegion(new CellRangeAddress(30, 30, 4, 4));
		
		Cell cell31 = row30.createCell(5);
		cell31.setCellValue((perf.get("信用卡系统_手机银行渠道") == null
				|| ((Map<String, Object>) perf.get("信用卡系统_手机银行渠道")).get("success_count") == null) ? "-"
						: Double.valueOf(((Map<String, Object>) perf.get("信用卡系统_手机银行渠道")).get("success_count").toString()).intValue() + "");
		cell31.setCellStyle(createCotentCellStyle);
		sheet.addMergedRegion(new CellRangeAddress(30, 30, 5, 5));
		
		Row row33 = sheet.getRow(33);
		row33.setHeightInPoints(25);
		Cell cell_type17 = row33.createCell(3);
		cell_type17.setCellValue("ATM渠道交易成功率");
		cell_type17.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(33, 35, 3, 3));
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell cell34a = row33.createCell(4);
		cell34a.setCellValue("系统成功交易量");
		cell34a.setCellStyle(style);
		sheet.addMergedRegion(new CellRangeAddress(33, 33, 4, 4));
		
		Cell cell34 = row33.createCell(5);
		cell34.setCellValue((perf.get("信用卡系统_ATM渠道") == null
				|| ((Map<String, Object>) perf.get("信用卡系统_ATM渠道")).get("success_count") == null) ? "-"
						: Double.valueOf(((Map<String, Object>) perf.get("信用卡系统_ATM渠道")).get("success_count").toString()).intValue() + "");
		cell34.setCellStyle(createCotentCellStyle);
		sheet.addMergedRegion(new CellRangeAddress(33, 33, 5, 5));
		
		Row row36 = sheet.getRow(36);
		row36.setHeightInPoints(25);
		Cell cell_type18 = row36.createCell(3);
		cell_type18.setCellValue("POS渠道交易成功率");
		cell_type18.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(36, 38, 3, 3));
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell cell37a = row36.createCell(4);
		cell37a.setCellValue("系统成功交易量");
		cell37a.setCellStyle(style);
		sheet.addMergedRegion(new CellRangeAddress(36, 36, 4, 4));
		
		Cell cell37 = row36.createCell(5);
		cell37.setCellValue((perf.get("信用卡系统_POS渠道") == null
				|| ((Map<String, Object>) perf.get("信用卡系统_POS渠道")).get("success_count") == null) ? "-"
						: Double.valueOf(((Map<String, Object>) perf.get("信用卡系统_POS渠道")).get("success_count").toString()).intValue() + "");
		cell37.setCellStyle(createCotentCellStyle);
		sheet.addMergedRegion(new CellRangeAddress(36, 36, 5, 5));
		
		Row row39 = sheet.getRow(39);
		row39.setHeightInPoints(25);
		Cell cell_type19 = row39.createCell(2);
		cell_type19.setCellValue("网上银行系统交易成功率");
		cell_type19.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(39, 44, 2, 2));
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell cell40a = row39.createCell(4);
		cell40a.setCellValue("系统成功交易量");
		cell40a.setCellStyle(style);
		sheet.addMergedRegion(new CellRangeAddress(39, 39, 4, 4));
		
		Cell cell40 = row39.createCell(5);
		cell40.setCellValue((perf.get("网上银行系统_个人网银") == null
				|| ((Map<String, Object>) perf.get("网上银行系统_个人网银")).get("success_count") == null) ? "-"
						: Double.valueOf(((Map<String, Object>) perf.get("网上银行系统_个人网银")).get("success_count").toString()).intValue() + "");
		cell40.setCellStyle(createCotentCellStyle);
		sheet.addMergedRegion(new CellRangeAddress(39, 39, 5, 5));
		
		Cell cell_type20 = row39.createCell(3);
		cell_type20.setCellValue("个人网银交易成功率");
		cell_type20.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(39, 41, 3, 3));
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Row row42 = sheet.getRow(42);
		row42.setHeightInPoints(25);
		Cell cell_type21 = row42.createCell(3);
		cell_type21.setCellValue("企业网银交易成功率");
		cell_type21.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(42, 44, 3, 3));
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell cell43a = row42.createCell(4);
		cell43a.setCellValue("系统成功交易量");
		cell43a.setCellStyle(style);
		sheet.addMergedRegion(new CellRangeAddress(42, 42, 4, 4));
		
		Cell cell43 = row42.createCell(5);
		cell43.setCellValue((perf.get("网上银行系统_企业网银") == null
				|| ((Map<String, Object>) perf.get("网上银行系统_企业网银")).get("success_count") == null) ? "-"
						: Double.valueOf(((Map<String, Object>) perf.get("网上银行系统_企业网银")).get("success_count").toString()).intValue() + "");
		cell43.setCellStyle(createCotentCellStyle);
		sheet.addMergedRegion(new CellRangeAddress(42, 42, 5, 5));
		
		Row row45 = sheet.getRow(45);
		row45.setHeightInPoints(25);
		Cell cell_type22 = row45.createCell(2);
		cell_type22.setCellValue("电话银行系统交易成功率");
		cell_type22.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(45, 47, 2, 3));
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell cell46a = row45.createCell(4);
		cell46a.setCellValue("系统成功交易量");
		cell46a.setCellStyle(style);
		sheet.addMergedRegion(new CellRangeAddress(45, 45, 4, 4));
		
		Cell cell46 = row45.createCell(5);
		cell46.setCellValue((perf.get("电话银行系统") == null
				|| ((Map<String, Object>) perf.get("电话银行系统")).get("success_count") == null) ? "-"
						: Double.valueOf(((Map<String, Object>) perf.get("电话银行系统")).get("success_count").toString()).intValue() + "");
		cell46.setCellStyle(createCotentCellStyle);
		sheet.addMergedRegion(new CellRangeAddress(45, 45, 5, 5));
		
		Row row48 = sheet.getRow(48);
		row48.setHeightInPoints(25);
		Cell cell_type23 = row48.createCell(2);
		cell_type23.setCellValue("手机银行交易成功率");
		cell_type23.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(48, 50, 2, 3));
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell cell49a = row48.createCell(4);
		cell49a.setCellValue("系统成功交易量");
		cell49a.setCellStyle(style);
		sheet.addMergedRegion(new CellRangeAddress(48, 48, 4, 4));
		
		Cell cell49 = row48.createCell(5);
		cell49.setCellValue((perf.get("手机银行") == null
				|| ((Map<String, Object>) perf.get("手机银行")).get("success_count") == null) ? "-"
						: Double.valueOf(((Map<String, Object>) perf.get("手机银行")).get("success_count").toString()).intValue() + "");
		cell49.setCellStyle(createCotentCellStyle);
		sheet.addMergedRegion(new CellRangeAddress(48, 48, 5, 5));
		
		Row row51 = sheet.createRow(51);
		row51.setHeightInPoints(25);
		Cell cell_type24 = row51.createCell(0);
		cell_type24.setCellValue("指标类型");
		cell_type24.setCellStyle(createCellStyle);
		sheet.addMergedRegion(new CellRangeAddress(51, 51, 0, 0));
		
		Cell cell_type25 = row51.createCell(1);
		cell_type25.setCellValue("指标名称");
		cell_type25.setCellStyle(createCellStyle);
		sheet.addMergedRegion(new CellRangeAddress(51, 51, 1, 1));
		
		Cell cell_type26 = row51.createCell(2);
		cell_type26.setCellValue("一级监测指标（5）");
		cell_type26.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(51, 51, 2, 3));
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell cell_typeNull = row51.createCell(2);
		cell_typeNull.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(51, 51, 4, 4));
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Row row52 = sheet.createRow(52);
		row52.setHeightInPoints(25);
		Cell cell_type27 = row52.createCell(0);
		cell_type27.setCellValue("规模型");
		cell_type27.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(52, 66, 0, 0));
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell cell52a = row52.createCell(4);
		cell52a.setCellValue("当期交易量");
		cell52a.setCellStyle(style);
		sheet.addMergedRegion(new CellRangeAddress(52, 52, 4, 4));
		
		Cell cell52 = row52.createCell(5);
		cell52.setCellValue((perf.get("网上银行交易变化率") == null
				|| ((Map<String, Object>) perf.get("网上银行交易变化率")).get("this_count") == null) ? "-"
						: Double.valueOf(((Map<String, Object>) perf.get("网上银行交易变化率")).get("this_count").toString()).intValue() + "");
		cell52.setCellStyle(createCotentCellStyle);
		sheet.addMergedRegion(new CellRangeAddress(52, 52, 5, 5));
		
		Cell cell_type28 = row52.createCell(1);
		cell_type28.setCellValue("主要电子渠道交易变化率");
		cell_type28.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(52, 66, 1, 1));
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell cell_type29 = row52.createCell(2);
		cell_type29.setCellValue("网上银行交易变化率");
		cell_type29.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(52, 54, 2, 3));
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Row row55 = sheet.getRow(55);
		row55.setHeightInPoints(25);
		Cell cell_type30 = row55.createCell(2);
		cell_type30.setCellValue("电话银行交易变化率");
		cell_type30.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(55, 57, 2, 3));
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell cell55a = row55.createCell(4);
		cell55a.setCellValue("当期交易量");
		cell55a.setCellStyle(style);
		sheet.addMergedRegion(new CellRangeAddress(55, 55, 4, 4));
		
		Cell cell55 = row55.createCell(5);
		cell55.setCellValue((perf.get("电话银行交易变化率") == null
				|| ((Map<String, Object>) perf.get("电话银行交易变化率")).get("this_count") == null) ? "-"
						: Double.valueOf(((Map<String, Object>) perf.get("电话银行交易变化率")).get("this_count").toString()).intValue() + "");
		cell55.setCellStyle(createCotentCellStyle);
		sheet.addMergedRegion(new CellRangeAddress(55, 55, 5, 5));
		
		Row row58 = sheet.getRow(58);
		row58.setHeightInPoints(25);
		Cell cell_type31 = row58.createCell(2);
		cell_type31.setCellValue("手机银行交易变化率");
		cell_type31.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(58, 60, 2, 3));
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell cell58a = row58.createCell(4);
		cell58a.setCellValue("当期交易量");
		cell58a.setCellStyle(style);
		sheet.addMergedRegion(new CellRangeAddress(58, 58, 4, 4));
		
		Cell cell58 = row58.createCell(5);
		cell58.setCellValue((perf.get("手机银行交易变化率") == null
				|| ((Map<String, Object>) perf.get("手机银行交易变化率")).get("this_count") == null) ? "-"
						: Double.valueOf(((Map<String, Object>) perf.get("手机银行交易变化率")).get("this_count").toString()).intValue() + "");
		cell58.setCellStyle(createCotentCellStyle);
		sheet.addMergedRegion(new CellRangeAddress(58, 58, 5, 5));
		
		Row row61 = sheet.getRow(61);
		row61.setHeightInPoints(25);
		Cell cell_type32 = row61.createCell(2);
		cell_type32.setCellValue("ATM交易变化率");
		cell_type32.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(61, 63, 2, 3));
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell cell61a = row61.createCell(4);
		cell61a.setCellValue("当期交易量");
		cell61a.setCellStyle(style);
		sheet.addMergedRegion(new CellRangeAddress(61, 61, 4, 4));
		
		Cell cell61 = row61.createCell(5);
		cell61.setCellValue((perf.get("ATM交易变化率") == null
				|| ((Map<String, Object>) perf.get("ATM交易变化率")).get("this_count") == null) ? "-"
						: Double.valueOf(((Map<String, Object>) perf.get("ATM交易变化率")).get("this_count").toString()).intValue() + "");
		cell61.setCellStyle(createCotentCellStyle);
		sheet.addMergedRegion(new CellRangeAddress(61, 61, 5, 5));
		
		Row row64 = sheet.getRow(64);
		row64.setHeightInPoints(25);
		Cell cell_type33 = row64.createCell(2);
		cell_type33.setCellValue("POS交易变化率");
		cell_type33.setCellStyle(createCellStyle);
		index = sheet.addMergedRegion(new CellRangeAddress(64, 66, 2, 3));
		setRegionStyle(sheet, sheet.getMergedRegion(index), createCellStyle);
		
		Cell cell64a = row64.createCell(4);
		cell64a.setCellValue("当期交易量");
		cell64a.setCellStyle(style);
		sheet.addMergedRegion(new CellRangeAddress(64, 64, 4, 4));
		
		Cell cell64 = row64.createCell(5);
		cell64.setCellValue((perf.get("POS交易变化率") == null
				|| ((Map<String, Object>) perf.get("POS交易变化率")).get("this_count") == null) ? "-"
						: Double.valueOf(((Map<String, Object>) perf.get("POS交易变化率")).get("this_count").toString()).intValue() + "");
		cell64.setCellStyle(createCotentCellStyle);
		sheet.addMergedRegion(new CellRangeAddress(64, 64, 5, 5));
		
	}

	private void createYjhTradeIndicatorHead(HSSFSheet sheet, int startRow, HSSFCellStyle createCellStyle) {
		Row row_col = sheet.createRow(startRow);
		Cell col_0 = row_col.createCell(0);
		row_col.setHeightInPoints(20);
		col_0.setCellValue("指标类型");
		col_0.setCellStyle(createCellStyle);
		sheet.addMergedRegion(new CellRangeAddress(2, 2, 0, 0));
		sheet.setColumnWidth(0, 8000);
		
		
		Cell col_1 = row_col.createCell(1);
		col_1.setCellValue("指标名称");
		col_1.setCellStyle(createCellStyle);
		sheet.addMergedRegion(new CellRangeAddress(2, 2, 1, 1));
		sheet.setColumnWidth(1, 8000);
		
		Cell col_2 = row_col.createCell(2);
		col_2.setCellValue("一级监测指标（6）");
		col_2.setCellStyle(createCellStyle);
		sheet.addMergedRegion(new CellRangeAddress(2, 2, 2, 2));
		sheet.setColumnWidth(2, 8000);
		
		Cell col_3 = row_col.createCell(3);
		col_3.setCellValue("二级监测指标（14）");
		col_3.setCellStyle(createCellStyle);
		sheet.addMergedRegion(new CellRangeAddress(2, 2, 3, 3));
		sheet.setColumnWidth(3, 10000);
		
		Cell col_4 = row_col.createCell(4);
		col_4.setCellValue("元数据");
		col_4.setCellStyle(createCellStyle);
		sheet.addMergedRegion(new CellRangeAddress(2, 2, 4, 4));
		sheet.setColumnWidth(4, 6000);
		
		Cell col_5 = row_col.createCell(5);
		col_5.setCellValue("值");
		col_5.setCellStyle(createCellStyle);
		sheet.addMergedRegion(new CellRangeAddress(2, 2, 5, 5));
		sheet.setColumnWidth(4, 7000);
	}
	
	
	@SuppressWarnings("unused")
	private void quick(List<PerformanceView> staticPerf, String orderBy,
			String orderDirection, int top) { 
		OrderClass[] list = new OrderClass[staticPerf.size()];
//		List<PerformanceView> staticPerf2 = new ArrayList<PerformanceView>();
		for (int i = 0; i < staticPerf.size(); i++) {
			OrderClass order = new OrderClass();
			PerformanceView performanceView = staticPerf.get(i);
			order.setPerformanceView(performanceView);
			if ("-".equals(performanceView.get(orderBy))) {
				// performanceView.put(orderBy, 0.0);
				order.setOrder(0.0);
			} else {
				order.setOrder(Double.parseDouble(performanceView.get(orderBy).toString()));
			}
			list[i] = order;
		}
		if (staticPerf.size() > 0) {    //查看数组是否为空  
			_quickSort(staticPerf, 0, staticPerf.size() - 1, orderBy);  
		}  
	}  
	
	private void _quickSort(List<PerformanceView> list, int low, int high, String orderBy) {  
		if (low < high) {  
			int middle = getMiddle(list, low, high, orderBy);  //将list数组进行一分为二  
			_quickSort(list, low, middle - 1, orderBy);        //对低字表进行递归排序  
			_quickSort(list, middle + 1, high, orderBy);       //对高字表进行递归排序  
		}  
	}  
	
	private int getMiddle(List<PerformanceView> list, int low, int high, String orderBy) {  
		PerformanceView tmp = list.get(low);    //数组的第一个作为中轴  
        while (low < high) {  
            while (low < high && ("-".equals(list.get(high).get(orderBy)) ? 0.0 : Double.parseDouble(list.get(high).get(orderBy).toString())) < ("-".equals(tmp.get(orderBy)) ? 0.0 : Double.parseDouble(tmp.get(orderBy).toString()))) {  
                high--;  
            }  
            list.set(low, list.get(high));   //比中轴小的记录移到低端  
            while (low < high && ("-".equals(list.get(low).get(orderBy)) ? 0.0 : Double.parseDouble(list.get(low).get(orderBy).toString())) > ("-".equals(tmp.get(orderBy)) ? 0.0 : Double.parseDouble(tmp.get(orderBy).toString()))) {  
                low++;  
            }  
            list.set(high, list.get(low));   //比中轴大的记录移到高端  
        }  
        list.set(low, tmp);              //中轴记录到尾  
        return low;                   //返回中轴的位置  
    }  
	
//	public static void main(String[] args) {  
//        // TODO Auto-generated method stub  
//         Integer[] list={34,3,53,2,23,7,14,10};  
//         ReportServiceImpl qs=new ReportServiceImpl();  
//         qs.quick(list);  
//         for(int i=0;i<list.length;i++){  
//             System.out.print(list[i]+" ");  
//         }  
//         System.out.println();  
//    }  
}